N = int(eval(input()))

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

for i in range(N-1):

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

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

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



C = [0] * (N-1)

stack=[0]

max_c=0

while stack:

    n=stack.pop()

    u=set()

    for to,i in E[n]:

        if C[i]!=0:

            u.add(C[i])

    c=1

    for to,i in E[n]:

        if C[i]!=0:

            continue

        while c in u:

            c+=1

        C[i]=c

        max_c=max(max_c,c)

        c+=1

        stack.append(to)



print(max_c)

print(('\n'.join(map(str,C))))
N = int(eval(input()))

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

for i in range(N-1):

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

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

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



C = [0] * (N-1)

stack=[0]

parent_e=[0]*N

max_c=0

while stack:

    n=stack.pop()

    c=1

    for to,i in E[n]:

        if n!=0 and parent_e[n]==i:

            continue

        c+=1 if n!=0 and C[parent_e[n]]==c else 0

        C[i]=c

        max_c=max(max_c,c)

        c+=1

        stack.append(to)

        parent_e[to]=i



print(max_c)

print(('\n'.join(map(str,C))))
N = int(eval(input()))
E = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    E[a - 1].append((b - 1, i))
    E[b - 1].append((a - 1, i))
C = [0] * (N - 1)
stack = [0]
max_c = 0
while stack:
    n = stack.pop()
    u = set()
    for to, i in E[n]:
        if C[i] != 0:
            u.add(C[i])
    c = 1
    for to, i in E[n]:
        if C[i] != 0:
            continue
        while c in u:
            c += 1
        C[i] = c
        max_c = max(max_c, c)
        c += 1
        stack.append(to)
print(max_c)
print(("\n".join(map(str, C))))

N = int(eval(input()))
E = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    E[a - 1].append((b - 1, i))
    E[b - 1].append((a - 1, i))
C = [0] * (N - 1)
stack = [0]
parent_e = [0] * N
max_c = 0
while stack:
    n = stack.pop()
    c = 1
    for to, i in E[n]:
        if n != 0 and parent_e[n] == i:
            continue
        c += 1 if n != 0 and C[parent_e[n]] == c else 0
        C[i] = c
        max_c = max(max_c, c)
        c += 1
        stack.append(to)
        parent_e[to] = i
print(max_c)
print(("\n".join(map(str, C))))

+parent_e = [0] * N -    u = set() -    for to, i in E[n]: -        if C[i] != 0: -            u.add(C[i]) -        if C[i] != 0: +        if n != 0 and parent_e[n] == i: -        while c in u: -            c += 1 +        c += 1 if n != 0 and C[parent_e[n]] == c else 0 +        parent_e[to] = i