#P6843. [BalticOI 2015] File Paths
[BalticOI 2015] File Paths
Description
A file must be located in a directory that contains many directories . The absolute file path of this file is . The root directory is denoted by . For a file placed directly under the root directory, its absolute file path has the form .
A symbolic link points to a named directory and can be seen as a shortcut. It can be placed in any directory. Note that a symbolic link cannot point to a file. For example, if we place under a symbolic link that points to , then , , and all refer to the same file . As another example, if we place under a symbolic link that points to , then , , and all refer to the same file . A symbolic link may point to the parent directory, a child directory, or even a directory on the same level, but operations such as , , and are not allowed.
Now the question is: is it possible, by introducing one symbolic link of length , to make it possible to find an absolute file path of some file whose length is exactly ?
Input Format
The first line contains three integers , representing the number of directories (excluding the root directory), the number of files, and the required path length .
The second line contains an integer , representing the length of the symbolic link.
The next lines each contain two integers , describing a directory: this directory has ID , and its parent directory has ID .
The next lines each contain two integers , describing a file: this file has length , and its parent directory has ID .
Output Format
Output lines. Each line is a string indicating whether, by introducing one symbolic link of length , it is possible to find an absolute file path of length exactly for file . If yes, output ; otherwise, output .
2 4 22
2
0 1
1 5
2 13
2 10
1 4
0 7
YES
YES
YES
NO
Hint
Sample 1 Explanation
Assume the symbolic link name is , the directory names are and , and the file names are , , , and . The root directory contains directory and file . Directory contains directory and file . Directory contains files and . A visual representation is:
/
|-- a
| |-- bbbbb
| | |-- ccccccccccccc
| | +-- dddddddddd
| +-- eeee
+-- fffffff
- For file , a path that satisfies the condition is .
- For file , a path that satisfies the condition is .
- For file , a path that satisfies the condition is .
- For file , no path satisfies the condition.
Constraints and Notes
This problem uses bundled tests.
- Subtask 1 (33 pts): .
- Subtask 2 (33 pts): , and the symbolic link is used at most once.
- Subtask 3 (34 pts): no special restrictions.
For of the testdata, , and .
Notes
Translated from BalticOI 2015 Day2 A File Paths。
Translated by ChatGPT 5
京公网安备 11011102002149号