#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 nn 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 11. A directed edge from knowledge point xx to knowledge point yy means that xx depends on yy. 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 xx that depends on other knowledge points, let maxx\max_x be the maximum difficulty among the knowledge points that xx depends on. Then, if xx depends on exactly one knowledge point whose difficulty is maxx\max_x, the difficulty of knowledge point xx is maxx\max_x; otherwise it is maxx+1\max_x + 1. 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 TT 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 nn denoting the number of knowledge points.
  • The second line contains nn integers a1,a2,,ana_1, a_2, \cdots, a_n, describing the difficulty of each knowledge point. If ai=1a_i = -1, it means the difficulty of knowledge point ii is not fixed; otherwise, the difficulty of knowledge point ii is fixed as aia_i.
  • The next n1n - 1 lines each contain two integers u,vu, v, 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 22 to 00 satisfies the conditions.

For the second test case, no matter how you assign the difficulty of knowledge point 22, the difficulty of knowledge point 11 will lead to a contradiction.

Constraints

For all testdata, 1T1051 \le T \le 10^5, 2n1052 \le n \le 10^5, 1ai109-1 \le a_i \le 10^9, 1u,vn1 \le u, v \le n.
It is guaranteed that, within a single test point, the sum of nn over all test cases does not exceed 2×1052 \times 10^5, and all edges given in each test case form an out-arborescence rooted at 11.

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