#P11755. [COCI 2024/2025 #5] 树树 2 / Stablo II
[COCI 2024/2025 #5] 树树 2 / Stablo II
Description
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.
Input Format
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.
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 and , and then with the second color, he painted edges , and .
Scoring
| Subtask | Points | Constraints |
|---|---|---|
| for all | ||
| No additional constraints. |
京公网安备 11011102002149号