There is a tree containing
The heaviness of the tree is defined as the average length of all the paths in the tree. Recall that the average in this case is
Evan is planning to modify the tree. He will choose two nodes,
- If the subtree rooted at node
is swapped with the subtree rooted at node (that is, and all of its descendants are moved to the location of , and vice versa), is the heaviness of the resultant tree lower, equal, or higher than the original tree's heaviness?
He will ask
Input Specification
The first line will contain two integers,
The next
The next
Output Specification
For each question, output -1
if the heaviness in the resultant tree is less than in the original tree, 0
if it is equal, and 1
if it is greater, on its own line.
Constraints
Subtask 1 [5%]
Subtask 2 [35%]
Subtask 3 [60%]
No additional constraints.
Sample Input 1
6 3
1 2
2 3
1 4
4 5
1 6
2 4
3 5
2 5
Sample Output 1
0
0
1
Explanation For Sample 1
The original tree is shown:
The heaviness is
For the third question, the tree looks like:
The new heaviness is
Sample Input 2
13 10
1 12
12 13
1 2
2 3
2 4
2 5
2 6
3 7
7 8
8 9
9 10
10 11
7 12
8 12
9 12
10 12
11 12
8 4
7 5
3 6
3 12
3 13
Sample Output 2
0
-1
-1
0
1
-1
-1
0
1
1
Comments