N = int(input())

AB = [tuple(map(int,input().split())) for i in range(N-1)]

es = [[] for i in range(N)]

ei = {}

for i,(a,b) in enumerate(AB):

    a,b = a-1,b-1

    es[a].append(b)

    es[b].append(a)

    ei[(a,b)] = ei[(b,a)] = i



max_e = root = 0

for i in range(N):

    if len(es[i]) > max_e:

        max_e = len(es[i])

        root = i



ans = [None]*(N-1)

visited = [0]*N

visited[root] = 1

stack = []

for i,to in enumerate(es[root]):

    ans[ei[(root,to)]] = i+1

    visited[to] = 1

    stack.append((to,i+1))



while stack:

    v,pc = stack.pop()

    c = 0

    for to in es[v]:

        if visited[to]: continue

        visited[to] = 1

        c += 1

        if c == pc:

            c += 1

        pi = ei[(v,to)]

        ans[pi] = c

        stack.append((to,c))



print(max(ans))

print(*ans, sep='\n')

import sys

sys.setrecursionlimit(10**8)

N = int(input())

AB = [tuple(map(int,input().split())) for i in range(N-1)]

es = [[] for i in range(N)]

for i,(a,b) in enumerate(AB):

    a,b = a-1,b-1

    es[a].append((b,i))

    es[b].append((a,i))



visited = [0]*N

ans = [None]*(N-1)



def dfs(v,c=-1):

    nc = 1

    for to,i in es[v]:

        if visited[to]: continue

        visited[v] = 1

        if nc==c:

            nc += 1

        ans[i] = nc

        dfs(to,nc)

        nc += 1

dfs(0)

print(max(ans))

print(*ans,sep='\n')

N = int(input())
AB = [tuple(map(int, input().split())) for i in range(N - 1)]
es = [[] for i in range(N)]
ei = {}
for i, (a, b) in enumerate(AB):
    a, b = a - 1, b - 1
    es[a].append(b)
    es[b].append(a)
    ei[(a, b)] = ei[(b, a)] = i
max_e = root = 0
for i in range(N):
    if len(es[i]) > max_e:
        max_e = len(es[i])
        root = i
ans = [None] * (N - 1)
visited = [0] * N
visited[root] = 1
stack = []
for i, to in enumerate(es[root]):
    ans[ei[(root, to)]] = i + 1
    visited[to] = 1
    stack.append((to, i + 1))
while stack:
    v, pc = stack.pop()
    c = 0
    for to in es[v]:
        if visited[to]:
            continue
        visited[to] = 1
        c += 1
        if c == pc:
            c += 1
        pi = ei[(v, to)]
        ans[pi] = c
        stack.append((to, c))
print(max(ans))
print(*ans, sep="\n")

import sys

sys.setrecursionlimit(10**8)
N = int(input())
AB = [tuple(map(int, input().split())) for i in range(N - 1)]
es = [[] for i in range(N)]
for i, (a, b) in enumerate(AB):
    a, b = a - 1, b - 1
    es[a].append((b, i))
    es[b].append((a, i))
visited = [0] * N
ans = [None] * (N - 1)


def dfs(v, c=-1):
    nc = 1
    for to, i in es[v]:
        if visited[to]:
            continue
        visited[v] = 1
        if nc == c:
            nc += 1
        ans[i] = nc
        dfs(to, nc)
        nc += 1


dfs(0)
print(max(ans))
print(*ans, sep="\n")

+import sys + +sys.setrecursionlimit(10**8) -ei = {} -    es[a].append(b) -    es[b].append(a) -    ei[(a, b)] = ei[(b, a)] = i -max_e = root = 0 -for i in range(N): -    if len(es[i]) > max_e: -        max_e = len(es[i]) -        root = i +    es[a].append((b, i)) +    es[b].append((a, i)) +visited = [0] * N -visited = [0] * N -visited[root] = 1 -stack = [] -for i, to in enumerate(es[root]): -    ans[ei[(root, to)]] = i + 1 -    visited[to] = 1 -    stack.append((to, i + 1)) -while stack: -    v, pc = stack.pop() -    c = 0 -    for to in es[v]: + + +def dfs(v, c=-1): +    nc = 1 +    for to, i in es[v]: -        visited[to] = 1 -        c += 1 -        if c == pc: -            c += 1 -        pi = ei[(v, to)] -        ans[pi] = c -        stack.append((to, c)) +        visited[v] = 1 +        if nc == c: +            nc += 1 +        ans[i] = nc +        dfs(to, nc) +        nc += 1 + + +dfs(0)