ccf#NOI2021A. 轻重边 (Light and Heavy Edges)
轻重边 (Light and Heavy Edges)
Description
Wayte has a tree with nodes, and every edge on the tree is either a light edge or a heavy edge. You're going to perform operations on the tree. Prior to any operation, all edges on the tree are light edges. There are two types of operations:
- Given two points and , first for each point along the path from to (including and ), you make all edges incident to light edges. Then change all edges in the path from to to heavy edges.
- Given two points and , you need to figure out the current count of heavy edges in the path from to .
Input Format
Each test contains multiple test cases. The first line contains a integer indicating the number of test cases. For each test case:
The first line contains two integers and . is the number of nodes, and is the number of operations.
Next lines each contain two integers , indicating an edge on the tree.
Next lines each contain three integers , describing an operation, where denotes operation type , and denotes operation type .
It is guaranteed that in tests.
Output Format
For each type- operation, print a line of one integer equal to its result.
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
1
3
2
1
Sample Explanation 1
After the st operation, heavy edges are: , , .
In the nd operation, involved heavy edge: .
In the rd operation, involved heavy edges: , , .
In the th operation, first and become light edges, then and become heavy edges.
In the th operation, involved heavy edges: , .
In the th operation, first becomes a light edge, then becomes a heavy edge.
In the th operation, involved heavy edge: .
Sample 2
See attached files edge2.in and edge2.ans. Constraints of this sample is the same as test cases .
Sample 3
See attached files edge3.in and edge2.ans. Constraints of this sample is the same as test cases .
Sample 4
See attached files edge4.in and edge4.ans. Constraints of this sample is the same as test cases .
Sample 5
See attached files edge5.in and edge5.ans. Constraints of this sample is the same as test cases .
Constraints and Specification
For all the tests, , .
Test Number | Special Case | |
---|---|---|
None | ||
None | ||
Special case : the tree is isomorphic to a chain.
Special case : and given by type- operations are directly connected by an edge.