import sys

from collections import deque

input = sys.stdin.readline

N = int(eval(input()))

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

for i in range(N-1):

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

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



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()))

bi=[0]* N

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

for i in range(N-1):

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

    bi[i]=b-1

    children[a-1].append(b-1)



queue = deque([0])

colors = [0] * N

maxColor = 0

while queue:

    node = queue.popleft()

    nodeColor = colors[node]

    color = 1

    for child in children[node]:

        if color == nodeColor: color += 1

        colors[child] = color

        queue.append(child)

        color += 1

    maxColor = max(maxColor, color-1)



print(maxColor)

for i in range(N-1):

    print((colors[bi[i]]))
import sys
from collections import deque

input = sys.stdin.readline
N = int(eval(input()))
X = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    X[a - 1].append((i, b - 1))
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()))
bi = [0] * N
children = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    bi[i] = b - 1
    children[a - 1].append(b - 1)
queue = deque([0])
colors = [0] * N
maxColor = 0
while queue:
    node = queue.popleft()
    nodeColor = colors[node]
    color = 1
    for child in children[node]:
        if color == nodeColor:
            color += 1
        colors[child] = color
        queue.append(child)
        color += 1
    maxColor = max(maxColor, color - 1)
print(maxColor)
for i in range(N - 1):
    print((colors[bi[i]]))

-X = [[] for _ in range(N)] +bi = [0] * N +children = [[] for _ in range(N)] -    X[a - 1].append((i, b - 1)) -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) +    bi[i] = b - 1 +    children[a - 1].append(b - 1) +queue = deque([0]) +colors = [0] * N +maxColor = 0 +while queue: +    node = queue.popleft() +    nodeColor = colors[node] +    color = 1 +    for child in children[node]: +        if color == nodeColor: +            color += 1 +        colors[child] = color +        queue.append(child) +        color += 1 +    maxColor = max(maxColor, color - 1) +print(maxColor) +for i in range(N - 1): +    print((colors[bi[i]]))