Light Heavy Edges
Time limit2sMemory limit1024 MB
Each update makes the path between a and b heavy and resets every other edge touching its vertices to light. Each query counts heavy edges on a path.
- Level
Medium7 of 10
- Topics
- Tree, Segment tree, Implementation
- Solved
- No attempts yet
Problem
You are given a tree with vertices. Each edge of the tree is either a light edge or a heavy edge. You must perform operations on the tree. Initially, all edges are light edges. There are two kinds of operations.
-
You are given two vertices and . For every vertex on the path between and (including and themselves), turn all edges connected to into light edges. Also turn all edges on the path between and into heavy edges.
-
You are given two vertices and . Compute the number of heavy edges on the path between and .
Input
The first line contains an integer , the number of test cases. Each test case starts with a line containing two integers and , where is the number of vertices and is the number of operations.
The next lines each contain two integers and , describing an edge of the tree.
The next lines each contain three integers , , , describing an operation. means an operation of the first type, and means an operation of the second type.
It is guaranteed that in every operation.
Output
For each operation of the second type, print the answer on its own line.
Constraints
For all test sets, and .