Stablo II
시간 제한3.5초메모리 제한2048 MB
트리에서 k번의 연산이 두 정점 사이 경로의 간선을 새 색으로 칠할 때, 각 간선의 최종 색을 출력한다.
문제
Patrik received a tree with vertices. He decided to paint the edges of that tree using different colors.
Initially, all edges of the tree are painted with color . He will use the colors in order from the first to the -th, where he will use the -th color to paint all the edges on the shortest path from the -th to the -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 and (, ), representing the number of vertices in the tree and the number of colors.
In the next lines, there are numbers and () — the -th edge connects the vertices and . It is guaranteed that the edges form a tree.
In the following lines, there are numbers and (), 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.