from collections import deque

import sys

input =sys.stdin.readline

N = int(eval(input()))



#構造入力

color_max =0

connection ={i:deque() for i in range(1,N+1)}

edge_color={}

A =[(-1,-1)]*N

for i in range(1,N):

    a,b = (int(x) for x in input().split())

    connection[a].append(b)

    connection[b].append(a)

    edge_color[(a,b)] =-1

    A[i] =(a,b)

    color_max =max(color_max, len(connection[a]) , len(connection[b]))



#幅優先探索で色塗る

passed =set()

#edge_color ={i:-1 for i in range(1,N+1)}

parent ={i:-1 for i in range(1,N+1)}

parent[1] =0

dq =deque()

dq.append(1)

color =0

#prev =0 #頂点１の親は０とする

edge_color[(0,1)] =0

#node_color[1] =0

while dq:

    now =dq.popleft()

    passed.add(now)

    na_max =max(parent[now],now)

    na_min =min(parent[now],now)

    i_color =edge_color[(na_min,na_max)]

    for next in connection[now]:

        if next in passed:

            continue

        else:

            i_color +=1

            n_max =max(now,next)

            n_min =min(now,next)

            edge_color[(n_min,n_max)] =(i_color)% color_max 

            dq.append(next)

            parent[next] =now

print(color_max)

del edge_color[(0,1)]

for i in range(1,N):

    print((edge_color[A[i]] +1 ))
"""2020/7/2再挑戦"""

#幅優先探索 親の頂点と色を覚えておく。親の色を除く＋1ずつ足していく。color_maxを超えたら余りをとる。

from collections import deque

N = int(eval(input()))

connection ={i:set() for i in range(1,N+1)}

connection_parent =[]

for i in range(1,N):

    a,b = (int(i) for i in input().split())

    connection[a].add(b)

    connection[b].add(a)

    connection_parent.append(b)



#最小の色数

c =[]

for i in list(connection.values()):

    c.append(len(i))

color_min =max(c)



#幅優先探索

start =1

color={i:0 for i in range(1,N+1)} #P:今の頂点と次への辺の色を記録(tuple)。

passed =set() # 通過した記録

dq =deque([start]) #スタートは1でいいのか？

color[start] =0

while len(dq) >0:

    now =dq.popleft()

    passed.add(now)

    c1 =color[now]

    for next in connection[now]:

        if next not in passed:

            c1 +=1

            c1 %=color_min

            color[next] =c1  #0 <=c <= color_min-1のため　＋１

            dq.append(next)

print(color_min)

for i in connection_parent:

    print((color[i] +1))
from collections import deque
import sys

input = sys.stdin.readline
N = int(eval(input()))
# 構造入力
color_max = 0
connection = {i: deque() for i in range(1, N + 1)}
edge_color = {}
A = [(-1, -1)] * N
for i in range(1, N):
    a, b = (int(x) for x in input().split())
    connection[a].append(b)
    connection[b].append(a)
    edge_color[(a, b)] = -1
    A[i] = (a, b)
    color_max = max(color_max, len(connection[a]), len(connection[b]))
# 幅優先探索で色塗る
passed = set()
# edge_color ={i:-1 for i in range(1,N+1)}
parent = {i: -1 for i in range(1, N + 1)}
parent[1] = 0
dq = deque()
dq.append(1)
color = 0
# prev =0 #頂点１の親は０とする
edge_color[(0, 1)] = 0
# node_color[1] =0
while dq:
    now = dq.popleft()
    passed.add(now)
    na_max = max(parent[now], now)
    na_min = min(parent[now], now)
    i_color = edge_color[(na_min, na_max)]
    for next in connection[now]:
        if next in passed:
            continue
        else:
            i_color += 1
            n_max = max(now, next)
            n_min = min(now, next)
            edge_color[(n_min, n_max)] = (i_color) % color_max
            dq.append(next)
            parent[next] = now
print(color_max)
del edge_color[(0, 1)]
for i in range(1, N):
    print((edge_color[A[i]] + 1))

"""2020/7/2再挑戦"""
# 幅優先探索 親の頂点と色を覚えておく。親の色を除く＋1ずつ足していく。color_maxを超えたら余りをとる。
from collections import deque

N = int(eval(input()))
connection = {i: set() for i in range(1, N + 1)}
connection_parent = []
for i in range(1, N):
    a, b = (int(i) for i in input().split())
    connection[a].add(b)
    connection[b].add(a)
    connection_parent.append(b)
# 最小の色数
c = []
for i in list(connection.values()):
    c.append(len(i))
color_min = max(c)
# 幅優先探索
start = 1
color = {i: 0 for i in range(1, N + 1)}  # P:今の頂点と次への辺の色を記録(tuple)。
passed = set()  # 通過した記録
dq = deque([start])  # スタートは1でいいのか？
color[start] = 0
while len(dq) > 0:
    now = dq.popleft()
    passed.add(now)
    c1 = color[now]
    for next in connection[now]:
        if next not in passed:
            c1 += 1
            c1 %= color_min
            color[next] = c1  # 0 <=c <= color_min-1のため　＋１
            dq.append(next)
print(color_min)
for i in connection_parent:
    print((color[i] + 1))

+"""2020/7/2再挑戦""" +# 幅優先探索 親の頂点と色を覚えておく。親の色を除く＋1ずつ足していく。color_maxを超えたら余りをとる。 -import sys -input = sys.stdin.readline -# 構造入力 -color_max = 0 -connection = {i: deque() for i in range(1, N + 1)} -edge_color = {} -A = [(-1, -1)] * N +connection = {i: set() for i in range(1, N + 1)} +connection_parent = [] -    a, b = (int(x) for x in input().split()) -    connection[a].append(b) -    connection[b].append(a) -    edge_color[(a, b)] = -1 -    A[i] = (a, b) -    color_max = max(color_max, len(connection[a]), len(connection[b])) -# 幅優先探索で色塗る -passed = set() -# edge_color ={i:-1 for i in range(1,N+1)} -parent = {i: -1 for i in range(1, N + 1)} -parent[1] = 0 -dq = deque() -dq.append(1) -color = 0 -# prev =0 #頂点１の親は０とする -edge_color[(0, 1)] = 0 -# node_color[1] =0 -while dq: +    a, b = (int(i) for i in input().split()) +    connection[a].add(b) +    connection[b].add(a) +    connection_parent.append(b) +# 最小の色数 +c = [] +for i in list(connection.values()): +    c.append(len(i)) +color_min = max(c) +# 幅優先探索 +start = 1 +color = {i: 0 for i in range(1, N + 1)}  # P:今の頂点と次への辺の色を記録(tuple)。 +passed = set()  # 通過した記録 +dq = deque([start])  # スタートは1でいいのか？ +color[start] = 0 +while len(dq) > 0: -    na_max = max(parent[now], now) -    na_min = min(parent[now], now) -    i_color = edge_color[(na_min, na_max)] +    c1 = color[now] -        if next in passed: -            continue -        else: -            i_color += 1 -            n_max = max(now, next) -            n_min = min(now, next) -            edge_color[(n_min, n_max)] = (i_color) % color_max +        if next not in passed: +            c1 += 1 +            c1 %= color_min +            color[next] = c1  # 0 <=c <= color_min-1のため　＋１ -            parent[next] = now -print(color_max) -del edge_color[(0, 1)] -for i in range(1, N): -    print((edge_color[A[i]] + 1)) +print(color_min) +for i in connection_parent: +    print((color[i] + 1))