import sys

input = sys.stdin.readline

N = int(eval(input()))

X = [[] for _ in range(N)]

P = [-1] * N

for i in range(N-1):

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

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

    #print(X)

    P[b-1] = a-1



Q = [(0, -1)]

ANS = [-1] * (N-1)

while Q:

    x, c0 = Q.pop()

    c = 1

    for i, y in X[x]:

        if c == c0: c += 1

        ANS[i] = c

        Q.append((y, c))

        c += 1



print((max(ANS)))

for ans in ANS:

    print(ans)
import sys

input = sys.stdin.readline

N = int(eval(input()))

X = [[] for _ in range(N)]

P = [-1] * N

for i in range(N-1):

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

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

    #print(X)

    #P[b-1] = a-1

#print(X)



Q = [(0, -1)]

ANS = [-1] * (N-1)

maxc = 0

while Q:

    x, c0 = Q.pop()

    c = 1

    for i, y in X[x]:

        if c == c0: c += 1

        ANS[i] = c

        if c>maxc:maxc=c

        Q.append((y, c))

        c += 1



print(maxc)

for ans in ANS:

    print(ans)
import sys

input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    X[a - 1].append((i, b - 1))
    # print(X)
    P[b - 1] = a - 1
Q = [(0, -1)]
ANS = [-1] * (N - 1)
while Q:
    x, c0 = Q.pop()
    c = 1
    for i, y in X[x]:
        if c == c0:
            c += 1
        ANS[i] = c
        Q.append((y, c))
        c += 1
print((max(ANS)))
for ans in ANS:
    print(ans)

import sys

input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
P = [-1] * N
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    X[a - 1].append((i, b - 1))
    # print(X)
    # P[b-1] = a-1
# print(X)
Q = [(0, -1)]
ANS = [-1] * (N - 1)
maxc = 0
while Q:
    x, c0 = Q.pop()
    c = 1
    for i, y in X[x]:
        if c == c0:
            c += 1
        ANS[i] = c
        if c > maxc:
            maxc = c
        Q.append((y, c))
        c += 1
print(maxc)
for ans in ANS:
    print(ans)

-    P[b - 1] = a - 1 +    # P[b-1] = a-1 +# print(X) +maxc = 0 +        if c > maxc: +            maxc = c -print((max(ANS))) +print(maxc)