There is a tree with
Given two vertices
and , for all on the path between and (including and themselves), you need to turn all edges connected with into light edges, and turn all edges on the path between and into heavy edges.Given two vertices
and , you need to compute the number of heavy edges on the path between and .
Input Specification
The first line is an integer
For each test case, the first line has two integers
For the next
For the next
It's guaranteed that
Output Specification
For each operation of the second type, output an integer denoting the answer to the query.
Sample Input 1
1
7 7
1 2
1 3
3 4
3 5
3 6
6 7
1 1 7
2 1 4
2 2 7
1 1 5
2 2 7
1 2 1
2 1 7
Sample Output 1
1
3
2
1
Explanation for Sample Output 1
After operation 1, the heavy edges are
In operation 2, the only heavy edge on the path from vertex
In operation 3, the heavy edges on the path from vertex
After operation 4,
In operation 5, the heavy edges on the path from vertex
After operation 6, edge
In operation 7, the heavy edge on the path from vertex
Additional Samples
Sample inputs and outputs can be found here.
- Sample 2 (
edge2.in
andedge2.ans
) corresponds to cases 3-6. - Sample 3 (
edge3.in
andedge3.ans
) corresponds to cases 9-10. - Sample 4 (
edge4.in
andedge4.ans
) corresponds to cases 11-14. - Sample 5 (
edge5.in
andedge5.ans
) corresponds to cases 17-20.
Constraints
For all test sets,
Test Case | Additional Constraints | |
---|---|---|
1~2 | None. | |
3~6 | ||
7~8 | A,B | |
9~10 | A | |
11~14 | B | |
15~16 | None. | |
17~20 |
Constraint A means the tree is a path.
Constraint B means for operations of the second type,
Comments