#キューとdictionaryを利用したBFS

from collections import deque



n = int(eval(input()))



ab = [list(map(int,input().split())) for i in range(n-1)]



ver = [[] for i in range(n)]



for i in range(n-1):

    a,b = ab[i][0],ab[i][1]

    ver[a-1].append(b-1)

    ver[b-1].append(a-1)



#print(ver)



color = [dict() for i in range(n)]

q = deque()

i = 1

for v in ver[0]:

    color[0][v] = i

    color[v][0] = i

    q.append((0,v))

    i += 1



#print(q)



while q:

    f,t = q.popleft()

    i = 1

    for v in ver[t]:

        if v == f:

            continue

        if i == color[f][t]:

            i += 1

        color[t][v] = i

        color[v][t] = i

        q.append((t,v))

        i += 1



#print(color)

#辞書のリストで辺の色を管理している

k = 0

for i in range(n):

    k = max(k,len(ver[i]))

print(k)

for i in range(n-1):

    a,b = ab[i][0],ab[i][1]

    print((color[a-1][b-1]))

#d3と同一解法

n=int(eval(input()))

import sys

#再帰関数の再帰回数を変更

sys.setrecursionlimit(10**6)

s=[[] for _ in range(n)]



for i in range(n-1):

    a,b=list(map(int,input().split()))

    s[a-1].append((b-1,i))

    s[b-1].append((a-1,i))



l=[0]*(n-1)



def dfs(node,pre_col,par):

    col=1

    for nei,i in s[node]:

        if nei==par:

            continue

        if col==pre_col:

            col+=1

        l[i]=col

        dfs(nei,col,node)

        col+=1

dfs(0,-1,-1)

print((max(l)))

for i in l:

    print(i)

# キューとdictionaryを利用したBFS
from collections import deque

n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n - 1)]
ver = [[] for i in range(n)]
for i in range(n - 1):
    a, b = ab[i][0], ab[i][1]
    ver[a - 1].append(b - 1)
    ver[b - 1].append(a - 1)
# print(ver)
color = [dict() for i in range(n)]
q = deque()
i = 1
for v in ver[0]:
    color[0][v] = i
    color[v][0] = i
    q.append((0, v))
    i += 1
# print(q)
while q:
    f, t = q.popleft()
    i = 1
    for v in ver[t]:
        if v == f:
            continue
        if i == color[f][t]:
            i += 1
        color[t][v] = i
        color[v][t] = i
        q.append((t, v))
        i += 1
# print(color)
# 辞書のリストで辺の色を管理している
k = 0
for i in range(n):
    k = max(k, len(ver[i]))
print(k)
for i in range(n - 1):
    a, b = ab[i][0], ab[i][1]
    print((color[a - 1][b - 1]))

# d3と同一解法
n = int(eval(input()))
import sys

# 再帰関数の再帰回数を変更
sys.setrecursionlimit(10**6)
s = [[] for _ in range(n)]
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    s[a - 1].append((b - 1, i))
    s[b - 1].append((a - 1, i))
l = [0] * (n - 1)


def dfs(node, pre_col, par):
    col = 1
    for nei, i in s[node]:
        if nei == par:
            continue
        if col == pre_col:
            col += 1
        l[i] = col
        dfs(nei, col, node)
        col += 1


dfs(0, -1, -1)
print((max(l)))
for i in l:
    print(i)

-# キューとdictionaryを利用したBFS -from collections import deque +# d3と同一解法 +n = int(eval(input())) +import sys -n = int(eval(input())) -ab = [list(map(int, input().split())) for i in range(n - 1)] -ver = [[] for i in range(n)] +# 再帰関数の再帰回数を変更 +sys.setrecursionlimit(10**6) +s = [[] for _ in range(n)] -    a, b = ab[i][0], ab[i][1] -    ver[a - 1].append(b - 1) -    ver[b - 1].append(a - 1) -# print(ver) -color = [dict() for i in range(n)] -q = deque() -i = 1 -for v in ver[0]: -    color[0][v] = i -    color[v][0] = i -    q.append((0, v)) -    i += 1 -# print(q) -while q: -    f, t = q.popleft() -    i = 1 -    for v in ver[t]: -        if v == f: +    a, b = list(map(int, input().split())) +    s[a - 1].append((b - 1, i)) +    s[b - 1].append((a - 1, i)) +l = [0] * (n - 1) + + +def dfs(node, pre_col, par): +    col = 1 +    for nei, i in s[node]: +        if nei == par: -        if i == color[f][t]: -            i += 1 -        color[t][v] = i -        color[v][t] = i -        q.append((t, v)) -        i += 1 -# print(color) -# 辞書のリストで辺の色を管理している -k = 0 -for i in range(n): -    k = max(k, len(ver[i])) -print(k) -for i in range(n - 1): -    a, b = ab[i][0], ab[i][1] -    print((color[a - 1][b - 1])) +        if col == pre_col: +            col += 1 +        l[i] = col +        dfs(nei, col, node) +        col += 1 + + +dfs(0, -1, -1) +print((max(l))) +for i in l: +    print(i)