#P11189. 「KDOI-10」水杯降温
「KDOI-10」水杯降温
Description
Little S has a tree with vertices, rooted at vertex . On vertex , there is a water cup with an initial temperature of .
Little S, who picked up a water cup and drank water without knowing the temperature and was scalded many times, decided to change all the temperatures of the water in the cups to .
Now, Little S can do the following two types of operations an arbitrary number of times (possibly zero):
- Use a heater at vertex . This will make the temperature of the water cups on all vertices in subtree increase by ;
- Or, blow a gust of wind from a leaf . This will make the temperature of the water cups on the route between and decrease by .
Help Little S determine whether he can make the temperature of all the water cups become .
Input Format
Each test contains multiple test cases.
The first line of the input contains a single integer — the id of the test. represents that this is a sample test.
The second line contains a single integer — the number of test cases.
For each test case:
- The first line contains a single integer — the number of vertices.
- The second line contains integers , in which is the parent vertex of vertex . It is guaranteed that .
- The third line contains integers — the initial temperature of the water cup on vertex .
Output Format
For each test case:
- If it is possible to make the temperature of all the water cups , print one line, a string
Huoyu; - If it is impossible to do so, print one line, a string
Shuiniao.
0
5
5
1 1 2 3
6 5 2 2 1
5
1 1 2 2
6 5 1 2 1
5
1 1 2 2
4 -1 5 -2 -2
5
1 1 2 2
6 -4 8 -3 -3
5
1 1 2 2
-1 -1 -1 -4 -1
Shuiniao
Huoyu
Shuiniao
Shuiniao
Huoyu
Hint
Sample 1 Explanation
Let be a heating operation on vertex , be a wind operation from vertex and be repeating the operations in for times.
- In the first, third and fourth test case, it can be proven that Little S can't make the temperature of all the water cups ;
- In the second test case, a possible operation sequence is ;
- For the fifth test case, a possible operation sequence is .
Sample 2
See water/water2.in and water/water2.ans in the attachments.
This sample satisfies the constraints of test .
Sample 3
See water/water3.in and water/water3.ans in the attachments.
This sample satisfies the constraints of test .
Sample 4
See water/water4.in and water/water4.ans in the attachments.
This sample satisfies the constraints of test .
Sample 5
See water/water5.in and water/water5.ans in the attachments.
This sample satisfies the constraints of test .
Sample 6
See water/water6.in and water/water6.ans in the attachments.
This sample satisfies the constraints of test .
Sample 7
See water/water7.in and water/water7.ans in the attachments.
This sample satisfies the constraints of test .
Constraints
Let be the sum of over all test cases in a single test.
For all the tests, it is guaranteed that:
- ;
- , ;
- For each , ;
- For each , .
| Test Id | Special Properties | |||
|---|---|---|---|---|
| - | ||||
| A | ||||
| B | ||||
| C | ||||
| - | ||||
- Property A: For each , ;
- Property B: For each , , where ;
- Property C: The depth of the tree does not exceed , where the depth of the tree denotes the maximum number of edges in the simple path from a node to the root.
Hints
The input and output files are huge in this problem, please use fast I/O methods.
京公网安备 11011102002149号