n = int(eval(input()))

edges = []



for id in range(n-1):

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

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



edges.sort()



used = [0]*(n)

ans = [0]*(n-1)

num = 1

prev = 0

for edge in edges:

    _from, to, id = edge

    if _from != prev:

        num = 1

    if used[_from] == num:

        num += 1

    ans[id] = num

    used[to] = num

    num += 1

    prev = _from



print((max(ans)))

for color in ans:

    print(color)

import sys

input = sys.stdin.readline



n = int(eval(input()))

edges = []



for id in range(n-1):

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

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



edges.sort()



used = [0]*(n)

ans = [0]*(n-1)

num = 1

prev = 0

for edge in edges:

    _from, to, id = edge

    if _from != prev:

        num = 1

    if used[_from] == num:

        num += 1

    ans[id] = num

    used[to] = num

    num += 1

    prev = _from



print((max(ans)))

for color in ans:

    print(color)

n = int(eval(input()))
edges = []
for id in range(n - 1):
    a, b = list(map(int, input().split()))
    edges.append([a - 1, b - 1, id])
edges.sort()
used = [0] * (n)
ans = [0] * (n - 1)
num = 1
prev = 0
for edge in edges:
    _from, to, id = edge
    if _from != prev:
        num = 1
    if used[_from] == num:
        num += 1
    ans[id] = num
    used[to] = num
    num += 1
    prev = _from
print((max(ans)))
for color in ans:
    print(color)

import sys

input = sys.stdin.readline
n = int(eval(input()))
edges = []
for id in range(n - 1):
    a, b = list(map(int, input().split()))
    edges.append([a - 1, b - 1, id])
edges.sort()
used = [0] * (n)
ans = [0] * (n - 1)
num = 1
prev = 0
for edge in edges:
    _from, to, id = edge
    if _from != prev:
        num = 1
    if used[_from] == num:
        num += 1
    ans[id] = num
    used[to] = num
    num += 1
    prev = _from
print((max(ans)))
for color in ans:
    print(color)

+import sys + +input = sys.stdin.readline