P11755 [COCI 2024/2025 #5] Stablo II

Background

译自 [COCI 2024/2025 #5](https://hsin.hr/coci/) T5。$\texttt{3.5s,0.5G}$。满分为 $120$。

Description

Patrik received a tree with $n$ vertices. He decided to paint the edges of that tree using $k$ different colors. Initially, all edges of the tree are painted with color $0$. He will use the colors in order from the first to the $k$-th, where he will use the $i$-th color to paint all the edges on the shortest path from the $x_i$-th to the $y_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 $n$ and $k$ ($2 ≤ n ≤ 10^6, 1 ≤ k ≤ 10^6$), representing the number of vertices in the tree and the number of colors. In the next $n − 1$ lines, there are numbers $u_i$ and $v_i$ ($1 ≤ u_i, v_i ≤ n$) — the $i$-th edge connects the vertices $u_i$ and $v_i$. It is guaranteed that the edges form a tree. In the following $k$ lines, there are numbers $x_i$ and $y_i$ ($1 ≤ 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.

Explanation/Hint

**Clarification of the first example:** With the first color, he painted edges $1$ and $4$, and then with the second color, he painted edges $1, 3$, and $5$. ### Scoring | Subtask | Points | Constraints | | :-: | :-: | :-: | | $1$ | $15$ | $u_i = i, v_i = i + 1$ for all $1\le i\le n-1$ | | $2$ | $15$ | $n, k ≤ 2000$ | | $3$ | $45$ | $n ≤ 10^5$ | | $4$ | $45$ | No additional constraints. |