luogu#P7735. [NOI2021] 轻重边
[NOI2021] 轻重边
Problem Description
Xiao W has a tree with nodes. Each edge in the tree can be either a light edge or a heavy edge. Next, you need to perform operations on the tree. Before all operations start, all edges in the tree are light edges. There are two types of operations:
- Given two nodes and , first, for every node on the path from to (including and ), you must change all edges incident to into light edges. Then, change all edges on the path from to into heavy edges.
- Given two nodes and , you need to compute how many heavy edges are currently on the path from to .
Input Format
This problem has multiple test cases. The first line of the input contains a positive integer , which indicates the number of test cases. For each test case:
The first line contains two integers and , where is the number of nodes and is the number of operations.
The next lines each contain two integers , representing an edge in the tree.
The next lines each contain three integers , describing an operation, where denotes an operation of type 1, and denotes an operation of type 2.
The data guarantees that .
Output Format
For each operation of type 2, output one line containing one integer, which is the answer.
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
Hint
[Sample Explanation #1]
After the 1st operation, the heavy edges are: , , .
In the 2nd operation, the heavy edges on the path are: .
In the 3rd operation, the heavy edges on the path are: , , .
In the 4th operation, first and become light edges, and then and become heavy edges.
In the 5th operation, the heavy edges on the path are: , .
In the 6th operation, first becomes a light edge, and then becomes a heavy edge.
In the 7th operation, the heavy edges on the path are: .
[Sample #2]
See the attachments edge/edge2.in and edge/edge2.ans.
The constraints of this sample are consistent with test points .
[Sample #3]
See the attachments edge/edge3.in and edge/edge3.ans.
The constraints of this sample are consistent with test points .
[Sample #4]
See the attachments edge/edge4.in and edge/edge4.ans.
The constraints of this sample are consistent with test points .
[Sample #5]
See the attachments edge/edge5.in and edge/edge5.ans.
The constraints of this sample are consistent with test points .
[Constraints]
For all testdata: , .
| Test Point ID | Special Property | |
|---|---|---|
| None | ||
| A, B | ||
| A | ||
| B | ||
| None | ||
Special property A: The tree is a chain.
Special property B: In each type 2 operation, and are directly connected by an edge.
Translated by ChatGPT 5