当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

BZOJ4122:[Baltic2015]File paths

题目描述

Byteasar likes to live risky. He runs with scissors, submits solutions to contest problems without testing on example inputs, and wants all his files to have path names that are exactly as long as the operating system allows (on Linux, for instance, this is 4095 characters).

When Byteasar is working on someone else's computer, it might turn out that not all of the files meet his criterion. In this case he tries to introduce symbolic links (symlinks) and use them for creating file paths. You are asked to figure out, for each file in the file system, whether Byteasar can introduce a single symbolic link (of length chosen by him in advance), so that this file can be referred to by a path name of length exactly k characters.
If a file of name file is contained in the chain of directories dir1, dir2, ..., dirj, then itsabsolute file path is /dir1/dir2/.../dirj/file. The root directory can be referred to as / and each file contained directly in this directory has the absolute path of the form /file. A symbolic link is a named shortcut to a directory, which can be placed in any directory in the file system. In this task symlinks to files are not allowed. Using a symlink, we can obtain alternative file paths. For example, if we introduced a symlink to / with name hello in /, then /dir/file,/hello/dir/file and /hello/hello/dir/file would all refer to the same file, but have different path name length. As another example, with a symlink to / with name hi in /dir, one could obtain file paths: /dir/file, /dir/hi/dir/file, /dir/hi/dir/hi/dir/file. Note that it is perfectly legal for symlinks to point upwards, downwards or sidewards in the file system hierarchy, and even back to the directory they are placed in. For the purpose of this problem, ./ or../ or // path components are not considered allowed in path names.
输入解释

The first line of input contains three positive integers: n (the number of directories other than the root directory), m (the number of files), and k (the desired path name length). The root directory has number 0, and all the remaining directories are numbered 1 through n. Files are numbered 1 through m. The second line contains the length s of the introduced symlink name (we don't care about the name itself, and assume it will not collide with anything else in the file system).

After that follow n lines describing the directories (other than the root directory) that exist in the file system. The i-th of those lines describes the directory number i and consists of two integers: Pi and Li. They specify that the directory number i has a name of length Li and its parent directory (i.e. the directory in which the i-th directory is directly contained) has number Pi. It is guaranteed that Pi<i.
Finally m lines follow with a description of the files in the file system. The j-th of those lines describes the file number j and consists of two integers: Pj and Lj. They specify that the file numberj has a name of length Lj and its parent directory has number Pj.
All files and directories will have names with positive length, and their absolute file paths will be at most k characters long.
输出解释

Your program should output m lines, one for each file. The J-th line should contain one word, YESor NO, answering the question: is it possible, by introducing a symlink of length s, to create a path name of length exactly k which refers to the file number j?

输入样例
2 4 22
2
0 1
1 5
2 13
2 10
1 4
0 7
输出样例
YES
YES
YES
NO
提示

Explanation to the example: Let us refer to the symlink as LL, the directory names as a andbbbbb, and the file names as ccccccccccccc, dddddddddd, eeee and fffffff, respectively. The root directory contains the directory a and the file fffffff; the directory a contains the directory bbbbb and the file eeee; and finally the directory bbbbb contains the filesccccccccccccc and dddddddddd.

/

  |- a

  |   |- bbbbb

  |   |   |- ccccccccccccc

  |   |   +- dddddddddd

  |   +- eeee

  +- fffffff

  

In the first case, the absolute file path /a/bbbbb/ccccccccccccc already has the desired length, so we don't even have to use the symlink. In the second case we can introduce the symlink /a/LL -> /a, and refer to /a/LL/bbbbb/dddddddddd. In the third case, we should introduce the symlink /a/LL -> /, and refer to /a/LL/a/LL/a/LL/a/eeee. In the fourth case we cannot reach the goal regardless of where we introduce the symlink.


1<=K,S<=1 000 000

N,M<=3000

求译文!请发至lydsy2012@163.com

BZPRO Powered by Remmina.
Github Repository
来自acmore.cc的附加信息
bzoj_id 4122
import_source_sha256 5ed5112ecd95128f6fa76bef2db569fa9d28daa1282130f87442eff1d40cbdc9
bzoj_checker_pending False

该题目包含在题集 大视野(八中)OJ 中

题目来源 BZOJ 4122

源链接: LOCAL-BZOJ4122

共提交 0 次

通过率 --%
时间上限 内存上限
10000 MS 256 MB