import sys

from collections import deque

input = sys.stdin.readline

N = int(eval(input()))

X = [deque() 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 = deque([(0, -1)])

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

cmax = 0

while Q:

    x, c0 = Q.pop()

    c = 1

    for i, y in X[x]:

        if c == c0: c += 1

        ANS[i] = c

        Q.appendleft((y, c))

        c += 1

    cmax = max(cmax, c-1)



print(cmax)

for ans in ANS:

    print(ans)
import sys

from collections import deque

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 = deque([(0, -1)])

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

cmax = 0

while Q:

    x, c0 = Q.pop()

    c = 1

    for i, y in X[x]:

        if c == c0: c += 1

        ANS[i] = c

        Q.appendleft((y, c))

        c += 1

    cmax = max(cmax, c-1)



print(cmax)

for ans in ANS:

    print(ans)
import sys
from collections import deque

input = sys.stdin.readline
N = int(eval(input()))
X = [deque() 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 = deque([(0, -1)])
ANS = [-1] * (N - 1)
cmax = 0
while Q:
    x, c0 = Q.pop()
    c = 1
    for i, y in X[x]:
        if c == c0:
            c += 1
        ANS[i] = c
        Q.appendleft((y, c))
        c += 1
    cmax = max(cmax, c - 1)
print(cmax)
for ans in ANS:
    print(ans)

import sys
from collections import deque

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 = deque([(0, -1)])
ANS = [-1] * (N - 1)
cmax = 0
while Q:
    x, c0 = Q.pop()
    c = 1
    for i, y in X[x]:
        if c == c0:
            c += 1
        ANS[i] = c
        Q.appendleft((y, c))
        c += 1
    cmax = max(cmax, c - 1)
print(cmax)
for ans in ANS:
    print(ans)

-X = [deque() for _ in range(N)] +X = [[] for _ in range(N)]