#初期入力
    import sys
    input = sys.stdin.readline
    import heapq
    N = int(input())
    connection   ={i:set() for i in range(1,N+1)}
    A            =[i for i in range(N-1)]
    for i in range(N-1):
        a,b = (int(x) for x in input().split())
        connection[a].add(b) # つながりを逆向きも含めて入力
        connection[b].add(a) # 
        A[i] =a,b            #色を出力するため
     
    #色の数(各頂点の最大値)
    color_max =0
    root =0
    for i,v in connection.items():
        if color_max < len(v) :
            color_max =len(v)
            root =i         #枝が一番多い所を根 ⇒スタート
     
    #各頂点に色を準備⇒辺の色決定
    aa=[]
    color =0                                 #辺に塗る色の候補
    node ={i:[] for i in range(1,N+1)} #頂点に使った色の管理
    edge ={}
    for a,b in A:
        edge[(a,b)] =-1                   #辺の色 -1で初期化
    now_set =set() #=start
    now_set.add(root) #=start
    next =set()
    next_next =set()
    passed ={i:False for i in range(1,N+1)}
    count =0
    while -1 in edge.values(): #全て辺の色が-1以外＝塗り終わった
        for now in now_set: #幅優先探索
            next =connection[now]
            for nex_2 in next:
                count =0
                if node[now] !=[]:
                    color =node[now][-1] +1
                while count < color_max:
                    q,color =divmod(color,color_max)
                    if color not in node[now] and color not in node[nex_2]:
                        n1,n2=0,0
                        if now > nex_2:
                            n1,n2 =nex_2,now
                        else:
                            n1,n2 =now,nex_2
                        edge[(n1,n2)] =color +1  #辺の色決定
                        node[now]   .append(color)
                        node[nex_2] .append(color)
                        passed[now] =True
                        #colored     =connection[nex_2] - passed
                        if passed[nex_2] ==False:
                            next_next.add(nex_2)  #つながっている頂点（次に探索する）
                        passed[nex_2] =nex_2
                        color   +=1
                        count   +=1
                        break
                    else:
                        color +=1
                        count +=1
        now_set     .clear()
        now_set     |=next_next
        next_next   .clear()
        
    #出力
    print(color_max)
    for i in A:
        print(edge[i])

### FIXED CODE ###

"""
参考    yy4さん 2019-11-24 21:24:43
516 ms          PyPy3 (2.4.0)
"""
#def solve():
from collections import deque
import sys

input = sys.stdin.readline

n = int(input())

g = tuple(set() for _ in range(n))
for idx in range(n - 1):
    a, b = (int(x) - 1 for x in input().split())
    g[a].add((b, idx))
    g[b].add((a, idx))

q = deque()
q.append((0, -1, -1))

e = [-1] * n  # e[-1]は使わない
used = [False] * n
used[0] = True
while q:
    v, v_idx, prev_color = q.popleft()
    curr = 1 if prev_color != 1 else 2
    for u, u_idx in g[v]:
        if used[u]:
            continue
        used[u] = True
        e[u_idx] = curr
        q.append((u, u_idx, curr))
        curr += 1
        if curr == prev_color:
            curr += 1

ret = e[:-1]
#return len(set(ret)), ret

    
#l, ret = solve()
l=len(set(ret))
print(l)
print(*ret, sep='\n')