시간 제한메모리 제한제출정답맞힌 사람정답 비율
3.5 초 2048 MB3616934.615%

문제

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.

입력

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.

출력

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

서브태스크

번호배점제한
115

$u_i = i$, $v_i = i + 1$ for each $i$

215

$n, k ≤ 2000$

345

$n ≤ 10^5$

445

No additional constraints.

예제 입력 1

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

예제 출력 1

2 0 2 1 2

예제 입력 2

5 4
1 2
2 3
3 4
4 5
5 5
4 3
2 1
2 4

예제 출력 2

3 4 4 0

예제 입력 3

5 4
3 5
2 3
4 3
5 1
4 1
5 5
4 2
1 5

예제 출력 3

1 3 3 4

채점 및 기타 정보

  • 예제는 채점하지 않는다.