#NOI2021A. 轻重边 (Light and Heavy Edges)

轻重边 (Light and Heavy Edges)

Description

Wayte has a tree with nn nodes, and every edge on the tree is either a light edge or a heavy edge. You're going to perform mm operations on the tree. Prior to any operation, all edges on the tree are light edges. There are two types of operations:

  1. Given two points aa and bb, first for each point xx along the path from aa to bb (including aa and bb), you make all edges incident to xx light edges. Then change all edges in the path from aa to bb to heavy edges.
  2. Given two points aa and bb, you need to figure out the current count of heavy edges in the path from aa to bb.

Input Format

Each test contains multiple test cases. The first line contains a integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and mm. nn is the number of nodes, and mm is the number of operations.

Next n1n-1 lines each contain two integers u,vu,v, indicating an edge on the tree.

Next mm lines each contain three integers opi,ai,biop_i,a_i,b_i, describing an operation, where opi=1op_i=1 denotes operation type 11, and opi=2op_i=2 denotes operation type 22.

It is guaranteed that aibia_i \neq b_i in tests.

Output Format

For each type-22 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 11st operation, heavy edges are: (1,3)(1,3), (3,6)(3,6), (6,7)(6,7).

In the 22nd operation, involved heavy edge: (1,3)(1,3).

In the 33rd operation, involved heavy edges: (1,3)(1,3), (3,6)(3,6), (6,7)(6,7).

In the 44th operation, first (1,3)(1,3) and (3,6)(3,6) become light edges, then (1,3)(1,3) and (3,5)(3,5) become heavy edges.

In the 55th operation, involved heavy edges: (1,3)(1,3), (6,7)(6,7).

In the 66th operation, first (1,3)(1,3) becomes a light edge, then (1,2)(1,2) becomes a heavy edge.

In the 77th operation, involved heavy edge: (6,7)(6,7).

Sample 2

See attached files edge2.in and edge2.ans. Constraints of this sample is the same as test cases 363 \sim 6.

Sample 3

See attached files edge3.in and edge2.ans. Constraints of this sample is the same as test cases 9109 \sim 10.

Sample 4

See attached files edge4.in and edge4.ans. Constraints of this sample is the same as test cases 111411 \sim 14.

Sample 5

See attached files edge5.in and edge5.ans. Constraints of this sample is the same as test cases 172017 \sim 20.

Constraints and Specification

For all the tests, T3T \leq 3, 1n,m1051 \leq n,m \leq 10^5.

Test Number n,mn,m \leq Special Case
121 \sim 2 100100 None
363 \sim 6 50005000
787 \sim 8 10510^5 A,BA,B
9109 \sim 10 AA
111411 \sim 14 BB
151615 \sim 16 2×1042 \times 10^4 None
172017 \sim 20 10510^5

Special case AA: the tree is isomorphic to a chain.

Special case BB: aia_i and bib_i given by type-22 operations are directly connected by an edge.