from collections import deque



n = int(eval(input()))



ab = [list(map(int,input().split())) for i in range(n-1)]



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



for i in range(n-1):

    a,b = ab[i][0],ab[i][1]

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

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



#print(ver)



color = [dict() for i in range(n)]

q = deque()

i = 1

for v in ver[0]:

    color[0][v] = i

    color[v][0] = i

    q.append((0,v))

    i += 1



#print(q)



while q:

    f,t = q.popleft()

    i = 1

    for v in ver[t]:

        if v == f:

            continue

        if i == color[f][t]:

            i += 1

        color[t][v] = i

        color[v][t] = i

        q.append((t,v))

        i += 1



#print(color)

k = 0

for i in range(n):

    k = max(k,len(ver[i]))

print(k)

for i in range(n-1):

    a,b = ab[i][0],ab[i][1]

    print((color[a-1][b-1]))

import sys

sys.setrecursionlimit(10**8)



n = int(eval(input()))

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



for i in range(n-1):

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

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

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



k = max(len(e) for e in edge)

print(k)



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



def dfs(v=0, p=-1, to_p_col = -1):

    col = 1

    for u, idx in edge[v]:

        if u != p:

            if col == to_p_col:

                col += 1

            ans[idx] = col

            dfs(u, v, col)

            col += 1

dfs()

print(('\n'.join(map(str,ans))))



from collections import deque

n = int(eval(input()))
ab = [list(map(int, input().split())) for i in range(n - 1)]
ver = [[] for i in range(n)]
for i in range(n - 1):
    a, b = ab[i][0], ab[i][1]
    ver[a - 1].append(b - 1)
    ver[b - 1].append(a - 1)
# print(ver)
color = [dict() for i in range(n)]
q = deque()
i = 1
for v in ver[0]:
    color[0][v] = i
    color[v][0] = i
    q.append((0, v))
    i += 1
# print(q)
while q:
    f, t = q.popleft()
    i = 1
    for v in ver[t]:
        if v == f:
            continue
        if i == color[f][t]:
            i += 1
        color[t][v] = i
        color[v][t] = i
        q.append((t, v))
        i += 1
# print(color)
k = 0
for i in range(n):
    k = max(k, len(ver[i]))
print(k)
for i in range(n - 1):
    a, b = ab[i][0], ab[i][1]
    print((color[a - 1][b - 1]))

import sys

sys.setrecursionlimit(10**8)
n = int(eval(input()))
edge = [[] for i in range(n)]
for i in range(n - 1):
    a, b = list(map(int, input().split()))
    edge[a - 1].append((b - 1, i))
    edge[b - 1].append((a - 1, i))
k = max(len(e) for e in edge)
print(k)
ans = [-1] * (n - 1)


def dfs(v=0, p=-1, to_p_col=-1):
    col = 1
    for u, idx in edge[v]:
        if u != p:
            if col == to_p_col:
                col += 1
            ans[idx] = col
            dfs(u, v, col)
            col += 1


dfs()
print(("\n".join(map(str, ans))))

-from collections import deque +import sys +sys.setrecursionlimit(10**8) -ab = [list(map(int, input().split())) for i in range(n - 1)] -ver = [[] for i in range(n)] +edge = [[] for i in range(n)] -    a, b = ab[i][0], ab[i][1] -    ver[a - 1].append(b - 1) -    ver[b - 1].append(a - 1) -# print(ver) -color = [dict() for i in range(n)] -q = deque() -i = 1 -for v in ver[0]: -    color[0][v] = i -    color[v][0] = i -    q.append((0, v)) -    i += 1 -# print(q) -while q: -    f, t = q.popleft() -    i = 1 -    for v in ver[t]: -        if v == f: -            continue -        if i == color[f][t]: -            i += 1 -        color[t][v] = i -        color[v][t] = i -        q.append((t, v)) -        i += 1 -# print(color) -k = 0 -for i in range(n): -    k = max(k, len(ver[i])) +    a, b = list(map(int, input().split())) +    edge[a - 1].append((b - 1, i)) +    edge[b - 1].append((a - 1, i)) +k = max(len(e) for e in edge) -for i in range(n - 1): -    a, b = ab[i][0], ab[i][1] -    print((color[a - 1][b - 1])) +ans = [-1] * (n - 1) + + +def dfs(v=0, p=-1, to_p_col=-1): +    col = 1 +    for u, idx in edge[v]: +        if u != p: +            if col == to_p_col: +                col += 1 +            ans[idx] = col +            dfs(u, v, col) +            col += 1 + + +dfs() +print(("\n".join(map(str, ans))))