from collections import deque



n = int(eval(input()))



adj = [[] for i in range(n)]

for i in range(n-1):

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

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

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



mx_color = 0    

for i in range(n):

    mx_color = max(mx_color,len(adj[i]))



dist = [-1]*n



res = [-1]*(n-1)



q = deque([])

q.append([0,-1])

dist[0] = 0



while len(q) > 0:

    v,c = q.popleft()

    color = 1

    

    if color == c:

        color += 1

        

    for nv,nc in adj[v]:

        if dist[nv] == -1:

            dist[nv] = dist[v] + 1

            q.append([nv,color])

            res[nc] = color

            color += 1

            if color == c:

                color += 1



print(mx_color)



for i in res:

    print(i)

import sys

 

n = int(eval(input()))

links = [set() for _ in range(n)]

for i, line in enumerate(sys.stdin):

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

    a -= 1

    b -= 1

    links[a].add((i, b))

    links[b].add((i, a))

 

ans = [-1] * (n - 1)

k = max(list(map(len, links)))

q = [(0, -1)]

fixed = set()

 

while q:

    v, c = q.pop()

    color = 1

    if c == color:

        color += 1

    for i, u in links[v]:

        if ans[i] != -1:

            continue

        ans[i] = color

        q.append((u, color))

        color += 1

        if c == color:

            color += 1

 

print(k)

print(('\n'.join(map(str, ans))))
from collections import deque

n = int(eval(input()))
adj = [[] for i in range(n)]
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    adj[a - 1].append([b - 1, i])
    adj[b - 1].append([a - 1, i])
mx_color = 0
for i in range(n):
    mx_color = max(mx_color, len(adj[i]))
dist = [-1] * n
res = [-1] * (n - 1)
q = deque([])
q.append([0, -1])
dist[0] = 0
while len(q) > 0:
    v, c = q.popleft()
    color = 1
    if color == c:
        color += 1
    for nv, nc in adj[v]:
        if dist[nv] == -1:
            dist[nv] = dist[v] + 1
            q.append([nv, color])
            res[nc] = color
            color += 1
            if color == c:
                color += 1
print(mx_color)
for i in res:
    print(i)

import sys

n = int(eval(input()))
links = [set() for _ in range(n)]
for i, line in enumerate(sys.stdin):
    a, b = list(map(int, line.split()))
    a -= 1
    b -= 1
    links[a].add((i, b))
    links[b].add((i, a))
ans = [-1] * (n - 1)
k = max(list(map(len, links)))
q = [(0, -1)]
fixed = set()
while q:
    v, c = q.pop()
    color = 1
    if c == color:
        color += 1
    for i, u in links[v]:
        if ans[i] != -1:
            continue
        ans[i] = color
        q.append((u, color))
        color += 1
        if c == color:
            color += 1
print(k)
print(("\n".join(map(str, ans))))

-from collections import deque +import sys -adj = [[] for i in range(n)] -for i in range(n - 1): -    a, b = list(map(int, input().split())) -    adj[a - 1].append([b - 1, i]) -    adj[b - 1].append([a - 1, i]) -mx_color = 0 -for i in range(n): -    mx_color = max(mx_color, len(adj[i])) -dist = [-1] * n -res = [-1] * (n - 1) -q = deque([]) -q.append([0, -1]) -dist[0] = 0 -while len(q) > 0: -    v, c = q.popleft() +links = [set() for _ in range(n)] +for i, line in enumerate(sys.stdin): +    a, b = list(map(int, line.split())) +    a -= 1 +    b -= 1 +    links[a].add((i, b)) +    links[b].add((i, a)) +ans = [-1] * (n - 1) +k = max(list(map(len, links))) +q = [(0, -1)] +fixed = set() +while q: +    v, c = q.pop() -    if color == c: +    if c == color: -    for nv, nc in adj[v]: -        if dist[nv] == -1: -            dist[nv] = dist[v] + 1 -            q.append([nv, color]) -            res[nc] = color +    for i, u in links[v]: +        if ans[i] != -1: +            continue +        ans[i] = color +        q.append((u, color)) +        color += 1 +        if c == color: -            if color == c: -                color += 1 -print(mx_color) -for i in res: -    print(i) +print(k) +print(("\n".join(map(str, ans))))