#P9386. [THUPC 2023 决赛] 大纲
[THUPC 2023 决赛] 大纲
Problem Description
Little I, little O, and little N are the authors of the ION syllabus. Little I is responsible for assigning a difficulty to each knowledge point.
The ION syllabus plans to include knowledge points. Among them, little I has assigned difficulties to some knowledge points according to his understanding, while the others have not been assigned yet.
There are dependency relations between knowledge points. These relations form exactly an out-arborescence rooted at . A directed edge from knowledge point to knowledge point means that depends on . The dependency relation is not transitive.
You need to tell little I whether the currently fixed difficulties are reasonable. We say the fixed difficulties are reasonable if and only if there exists a way to assign difficulties to all knowledge points whose difficulties are not yet fixed, such that all the following conditions hold:
- The difficulty of each knowledge point is a non-negative integer.
- For each knowledge point that depends on other knowledge points, let be the maximum difficulty among the knowledge points that depends on. Then, if depends on exactly one knowledge point whose difficulty is , the difficulty of knowledge point is ; otherwise it is . For knowledge points that do not depend on any other knowledge points, there are no other constraints.
Input Format
This problem contains multiple test cases. The first line contains an integer denoting the number of test cases, followed by the input of each test case in order.
For each test case:
- The first line contains an integer denoting the number of knowledge points.
- The second line contains integers , describing the difficulty of each knowledge point. If , it means the difficulty of knowledge point is not fixed; otherwise, the difficulty of knowledge point is fixed as .
- The next lines each contain two integers , denoting a directed edge in the out-arborescence formed by the dependency relations.
Output Format
For each test case, output one line. If the difficulties are reasonable, output Reasonable; otherwise output Unreasonable.
2
3
0 -1 0
1 2
2 3
3
0 -1 0
1 2
1 3
Reasonable
Unreasonable
Hint
Explanation for Sample 1
For the first test case, setting the difficulty of knowledge point to satisfies the conditions.
For the second test case, no matter how you assign the difficulty of knowledge point , the difficulty of knowledge point will lead to a contradiction.
Constraints
For all testdata, , , , .
It is guaranteed that, within a single test point, the sum of over all test cases does not exceed , and all edges given in each test case form an out-arborescence rooted at .
Postscript
The syllabus was published. A few days later, little I submitted problems to the ION contest, but found that someone had secretly changed the difficulty table, causing his problems to go beyond the syllabus. Therefore, little I had to submit the problems to CPUHT.
Source
From the finals of the 2023 Tsinghua University Student Programming Contest and Collegiate Invitational (THUPC2023).
Resources such as editorials can be found at https://github.com/THUSAAC/THUPC2023.
Translated by ChatGPT 5