Stablo II

시간 제한3.5초메모리 제한2048 MB

요약
트리에서 k번의 연산이 두 정점 사이 경로의 간선을 새 색으로 칠할 때, 각 간선의 최종 색을 출력한다.
난이도

어려움10점 중 8점

유형
트리, DFS, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

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 x_ix\_i-th to the y_iy\_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 nn and kk (2≤n≤1062 ≤ n ≤ 10^6, 1≤k≤1061 ≤ k ≤ 10^6), representing the number of vertices in the tree and the number of colors.

In the next n−1n - 1 lines, there are numbers u_iu\_i and v_iv\_i (1≤u_i,v_i≤n1 ≤ u\_i , v\_i ≤ n) — the ii-th edge connects the vertices u_iu\_i and v_iv\_i. It is guaranteed that the edges form a tree.

In the following kk lines, there are numbers x_ix\_i and y_iy\_i (1≤x_i,y_i≤n1 ≤ 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.

예제3

  1. 예제 1

    입력
    6 2
    1 2
    2 3
    2 4
    1 5
    4 6
    5 2
    6 1
    
    예상 출력
    2 0 2 1 2
    
  2. 예제 2

    입력
    5 4
    1 2
    2 3
    3 4
    4 5
    5 5
    4 3
    2 1
    2 4
    
    예상 출력
    3 4 4 0
    
  3. 예제 3

    입력
    5 4
    3 5
    2 3
    4 3
    5 1
    4 1
    5 5
    4 2
    1 5
    
    예상 출력
    1 3 3 4