import sys

input = sys.stdin.readline





n = int(eval(input()))

ans = [0]*(n-1)

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

used = [0]*n



for i in range(n-1):

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

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



for node in range(n):

    unable = used[node]

    color = 1



    for to, id in edges[node]:

        if color == unable:

            color += 1

        ans[id] = color

        used[to] = color

        color += 1



print((max(used)))

for color in ans:

    print(color)

import sys

read = sys.stdin.read





n, *ab = list(map(int, read().split()))

ans = [0]*(n-1)

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

used = [0]*n



for i, a, b in zip(list(range(n-1)), *[iter(ab)] * 2):

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



for node in range(n):

    unable = used[node]

    color = 1



    for to, id in edges[node]:

        if color == unable:

            color += 1

        ans[id] = str(color)

        used[to] = color

        color += 1



print((max(used)))

print(('\n'.join(ans)))
import sys

input = sys.stdin.readline
n = int(eval(input()))
ans = [0] * (n - 1)
edges = [[] for _ in range(n)]
used = [0] * n
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    edges[a - 1].append([b - 1, i])
for node in range(n):
    unable = used[node]
    color = 1
    for to, id in edges[node]:
        if color == unable:
            color += 1
        ans[id] = color
        used[to] = color
        color += 1
print((max(used)))
for color in ans:
    print(color)

import sys

read = sys.stdin.read
n, *ab = list(map(int, read().split()))
ans = [0] * (n - 1)
edges = [[] for _ in range(n)]
used = [0] * n
for i, a, b in zip(list(range(n - 1)), *[iter(ab)] * 2):
    edges[a - 1].append([b - 1, i])
for node in range(n):
    unable = used[node]
    color = 1
    for to, id in edges[node]:
        if color == unable:
            color += 1
        ans[id] = str(color)
        used[to] = color
        color += 1
print((max(used)))
print(("\n".join(ans)))

-input = sys.stdin.readline -n = int(eval(input())) +read = sys.stdin.read +n, *ab = list(map(int, read().split())) -for i in range(n - 1): -    a, b = list(map(int, input().split())) +for i, a, b in zip(list(range(n - 1)), *[iter(ab)] * 2): -        ans[id] = color +        ans[id] = str(color) -for color in ans: -    print(color) +print(("\n".join(ans)))