#P11755. [COCI 2024/2025 #5] 树树 2 / Stablo II

[COCI 2024/2025 #5] 树树 2 / Stablo II

Description

Patrik received a tree with nn vertices. He decided to paint the edges of that tree using kk different colors.

Initially, all edges of the tree are painted with color 00. He will use the colors in order from the first to the kk-th, where he will use the ii-th color to paint all the edges on the shortest path from the xix_i-th to the yiy_i-th node. If an edge on that path is already painted, the new color will overwrite the old one.

Help Patrik determine the final color of each edge.

Input Format

In the first line of input, there are numbers nn and kk (2n106,1k1062 ≤ n ≤ 10^6, 1 ≤ k ≤ 10^6), representing the number of vertices in the tree and the number of colors.

In the next n1n − 1 lines, there are numbers uiu_i and viv_i (1ui,vin1 ≤ u_i, v_i ≤ n) — the ii-th edge connects the vertices uiu_i and viv_i. It is guaranteed that the edges form a tree.

In the following kk lines, there are numbers xix_i and yiy_i (1xi,yin1 ≤ x_i, y_i ≤ n), representing the nodes between which Patrik paints the edges.

Output Format

In a single line, print the final color of each edge in the order they were given in the input.

6 2
1 2
2 3
2 4
1 5
4 6
5 2
6 1
2 0 2 1 2
5 4
1 2
2 3
3 4
4 5
5 5
4 3
2 1
2 4
3 4 4 0
5 4
3 5
2 3
4 3
5 1
4 1
5 5
4 2
1 5
1 3 3 4

Hint

Clarification of the first example:

With the first color, he painted edges 11 and 44, and then with the second color, he painted edges 1,31, 3, and 55.

Scoring

Subtask Points Constraints
11 1515 ui=i,vi=i+1u_i = i, v_i = i + 1 for all 1in11\le i\le n-1
22 n,k2000n, k ≤ 2000
33 4545 n105n ≤ 10^5
44 No additional constraints.