92 atcoder#ABC146D. [ABC146D] Coloring Edges on Tree
[ABC146D] Coloring Edges on Tree
Score : points
Problem Statement
Given is a tree with vertices. The vertices are numbered through , and the -th edge connects Vertex and Vertex .
Consider painting the edges in with some number of colors. We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.
Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.
Constraints
- All values in input are integers.
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print lines.
The first line should contain , the number of colors used.
The -th line should contain , the integer representing the color of the -th edge, where must hold.
If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.
3
1 2
2 3
2
1
2
8
1 2
2 3
2 4
2 5
4 7
5 6
6 8
4
1
2
3
4
1
1
2
6
1 2
1 3
1 4
1 5
1 6
5
1
2
3
4
5