QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#6654. Outline

统计

Xiao I, Xiao O, and Xiao N are the authors of the ION syllabus, and Xiao I is responsible for assigning a difficulty level to each knowledge point.

The ION syllabus plans to include $n$ knowledge points. Xiao I has already assigned difficulty levels to some of these knowledge points based on his own judgment, while some knowledge points remain without a difficulty level.

There are dependency relationships between the knowledge points, which form an out-tree rooted at 1. A directed edge from knowledge point $x$ to knowledge point $y$ indicates that $x$ depends on $y$. Dependency relationships are not transitive.

You need to tell Xiao I whether the currently determined difficulty levels are reasonable. We consider the determined difficulty levels to be reasonable if and only if there exists a way to assign difficulty levels to all currently unassigned knowledge points such that all of the following conditions are met:

  • The difficulty level of every knowledge point is a non-negative integer.
  • For every knowledge point $x$ that depends on other knowledge points, let $\max_x$ be the maximum difficulty level among all knowledge points that $x$ depends on. If $x$ depends on exactly one knowledge point with difficulty $\max_x$, then the difficulty of $x$ is $\max_x$; otherwise, the difficulty of $x$ is $\max_x + 1$. For knowledge points that do not depend on any other knowledge points, there are no other restrictions.

Input

The input is read from standard input.

This problem contains multiple test cases. The first line contains an integer $T$, representing the number of test cases. The test cases follow sequentially.

For each test case: The first line contains an integer $n$, representing the number of knowledge points. The second line contains $n$ integers $a_1, a_2, \dots, a_n$, describing the difficulty of each knowledge point. If $a_i = -1$, it means the difficulty of knowledge point $i$ is not yet determined; otherwise, the difficulty of knowledge point $i$ is determined as $a_i$. * The next $n - 1$ lines each contain two integers $u, v$, representing a directed edge in the out-tree formed by the dependency relationships.

Output

Output to standard output.

For each test case, output one line: if the difficulty levels are reasonable, output Reasonable, otherwise output Unreasonable.

Examples

Input 1

2
3
0 -1 0
1 2
2 3
3
0 -1 0
1 2
1 3

Output 1

Reasonable
Unreasonable

Note 1

For the first test case, setting the difficulty of knowledge point 2 to 0 satisfies the conditions. For the second test case, no matter how the difficulty of knowledge point 2 is assigned, the difficulty of knowledge point 1 will result in a contradiction.

Constraints

For all test cases, $1 \le T \le 10^5$, $2 \le n \le 10^5$, $-1 \le a_i \le 10^9$, $1 \le u, v \le n$. It is guaranteed that the sum of $n$ over all test cases in a single test file does not exceed $2 \times 10^5$, and the edges in each test case form an out-tree rooted at 1.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.