from collections import deque





N = int(eval(input()))

B = []

L = []

for i in range(N-1):

    ta,tb = list(map(int,input().split()))

    B.append(ta)

    B.append(tb)

    L.append([ta,tb])

B =B[1::2]

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

for a, b in L:

    E[a].append(b)



Q = deque([1])

C = [0] * (N + 1)

while Q:

    v = Q.popleft()

    c = 0

    for u in E[v]:

        c += 1 + (c + 1 == C[v])

        C[u] = c

        Q.append(u)



print((max(C)))

print(("\n".join(str(C[b]) for b in B)))

def main():



    from collections import deque





    N = int(eval(input()))

    B = []

    L = []

    for i in range(N-1):

        ta,tb = list(map(int,input().split()))

        B.append(ta)

        B.append(tb)

        L.append([ta,tb])

    B =B[1::2]

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

    for a, b in L:

        E[a].append(b)



    Q = deque([1])

    C = [0] * (N + 1)

    while Q:

        v = Q.popleft()

        c = 0

        for u in E[v]:

            c += 1 + (c + 1 == C[v])

            C[u] = c

            Q.append(u)



    print((max(C)))

    print(("\n".join(str(C[b]) for b in B)))

main()
from collections import deque

N = int(eval(input()))
B = []
L = []
for i in range(N - 1):
    ta, tb = list(map(int, input().split()))
    B.append(ta)
    B.append(tb)
    L.append([ta, tb])
B = B[1::2]
E = [[] for _ in range(N + 1)]
for a, b in L:
    E[a].append(b)
Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)
print((max(C)))
print(("\n".join(str(C[b]) for b in B)))

def main():
    from collections import deque

    N = int(eval(input()))
    B = []
    L = []
    for i in range(N - 1):
        ta, tb = list(map(int, input().split()))
        B.append(ta)
        B.append(tb)
        L.append([ta, tb])
    B = B[1::2]
    E = [[] for _ in range(N + 1)]
    for a, b in L:
        E[a].append(b)
    Q = deque([1])
    C = [0] * (N + 1)
    while Q:
        v = Q.popleft()
        c = 0
        for u in E[v]:
            c += 1 + (c + 1 == C[v])
            C[u] = c
            Q.append(u)
    print((max(C)))
    print(("\n".join(str(C[b]) for b in B)))


main()

-from collections import deque +def main(): +    from collections import deque -N = int(eval(input())) -B = [] -L = [] -for i in range(N - 1): -    ta, tb = list(map(int, input().split())) -    B.append(ta) -    B.append(tb) -    L.append([ta, tb]) -B = B[1::2] -E = [[] for _ in range(N + 1)] -for a, b in L: -    E[a].append(b) -Q = deque([1]) -C = [0] * (N + 1) -while Q: -    v = Q.popleft() -    c = 0 -    for u in E[v]: -        c += 1 + (c + 1 == C[v]) -        C[u] = c -        Q.append(u) -print((max(C))) -print(("\n".join(str(C[b]) for b in B))) +    N = int(eval(input())) +    B = [] +    L = [] +    for i in range(N - 1): +        ta, tb = list(map(int, input().split())) +        B.append(ta) +        B.append(tb) +        L.append([ta, tb]) +    B = B[1::2] +    E = [[] for _ in range(N + 1)] +    for a, b in L: +        E[a].append(b) +    Q = deque([1]) +    C = [0] * (N + 1) +    while Q: +        v = Q.popleft() +        c = 0 +        for u in E[v]: +            c += 1 + (c + 1 == C[v]) +            C[u] = c +            Q.append(u) +    print((max(C))) +    print(("\n".join(str(C[b]) for b in B))) + + +main()