92 #ABC146D. [ABC146D] Coloring Edges on Tree

[ABC146D] Coloring Edges on Tree

Score : 400400 points

Problem Statement

Given is a tree GG with NN vertices. The vertices are numbered 11 through NN, and the ii-th edge connects Vertex aia_i and Vertex bib_i.

Consider painting the edges in GG 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

  • 2N1052 \le N \le 10^5
  • 1ai<biN1 \le a_i \lt b_i \le N
  • All values in input are integers.
  • The given graph is a tree.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aN1a_{N-1} bN1b_{N-1}

Output

Print NN lines.

The first line should contain KK, the number of colors used.

The (i+1)(i+1)-th line (1iN1)(1 \le i \le N-1) should contain cic_i, the integer representing the color of the ii-th edge, where 1ciK1 \le c_i \le K 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