import sys

sys.setrecursionlimit(10**9)



N = int(eval(input()))

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

edges = []

for _ in range(N-1):

    A, B = list(map(int, input().split()))

    A, B = A-1, B-1

    adjL[A].append(B)

    adjL[B].append(A)

    edges.append((A, B))



colors = dict()

def dfs(vNow, vPar, color):

    c = 1

    for v2 in adjL[vNow]:

        if v2 == vPar: continue

        if c == color:

            c += 1

        A, B = vNow, v2

        if A > B:

            A, B = B, A

        colors[(A, B)] = c

        dfs(v2, vNow, c)

        c += 1



dfs(0, -1, 0)

#print(colors)



anss = []

for A, B in edges:

    anss.append(colors[(A, B)])



print((max(colors.values())))

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

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**9)



def solve():

    N = int(eval(input()))

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

    for i in range(N-1):

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

        a, b = a-1, b-1

        adjL[a].append((b, i))

        adjL[b].append((a, i))



    def dfs(vNow, vPar, clrPar):

        clr = 1

        for v2, i in adjL[vNow]:

            if v2 == vPar: continue

            if clr == clrPar:

                clr += 1

            anss[i] = clr

            dfs(v2, vNow, clr)

            clr += 1



    anss = [0] * (N-1)

    dfs(0, -1, 0)



    print((max(anss)))

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





solve()

import sys

sys.setrecursionlimit(10**9)
N = int(eval(input()))
adjL = [[] for _ in range(N)]
edges = []
for _ in range(N - 1):
    A, B = list(map(int, input().split()))
    A, B = A - 1, B - 1
    adjL[A].append(B)
    adjL[B].append(A)
    edges.append((A, B))
colors = dict()


def dfs(vNow, vPar, color):
    c = 1
    for v2 in adjL[vNow]:
        if v2 == vPar:
            continue
        if c == color:
            c += 1
        A, B = vNow, v2
        if A > B:
            A, B = B, A
        colors[(A, B)] = c
        dfs(v2, vNow, c)
        c += 1


dfs(0, -1, 0)
# print(colors)
anss = []
for A, B in edges:
    anss.append(colors[(A, B)])
print((max(colors.values())))
print(("\n".join(map(str, anss))))

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**9)


def solve():
    N = int(eval(input()))
    adjL = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = list(map(int, input().split()))
        a, b = a - 1, b - 1
        adjL[a].append((b, i))
        adjL[b].append((a, i))

    def dfs(vNow, vPar, clrPar):
        clr = 1
        for v2, i in adjL[vNow]:
            if v2 == vPar:
                continue
            if clr == clrPar:
                clr += 1
            anss[i] = clr
            dfs(v2, vNow, clr)
            clr += 1

    anss = [0] * (N - 1)
    dfs(0, -1, 0)
    print((max(anss)))
    print(("\n".join(map(str, anss))))


solve()

+input = sys.stdin.readline -N = int(eval(input())) -adjL = [[] for _ in range(N)] -edges = [] -for _ in range(N - 1): -    A, B = list(map(int, input().split())) -    A, B = A - 1, B - 1 -    adjL[A].append(B) -    adjL[B].append(A) -    edges.append((A, B)) -colors = dict() -def dfs(vNow, vPar, color): -    c = 1 -    for v2 in adjL[vNow]: -        if v2 == vPar: -            continue -        if c == color: -            c += 1 -        A, B = vNow, v2 -        if A > B: -            A, B = B, A -        colors[(A, B)] = c -        dfs(v2, vNow, c) -        c += 1 +def solve(): +    N = int(eval(input())) +    adjL = [[] for _ in range(N)] +    for i in range(N - 1): +        a, b = list(map(int, input().split())) +        a, b = a - 1, b - 1 +        adjL[a].append((b, i)) +        adjL[b].append((a, i)) + +    def dfs(vNow, vPar, clrPar): +        clr = 1 +        for v2, i in adjL[vNow]: +            if v2 == vPar: +                continue +            if clr == clrPar: +                clr += 1 +            anss[i] = clr +            dfs(v2, vNow, clr) +            clr += 1 + +    anss = [0] * (N - 1) +    dfs(0, -1, 0) +    print((max(anss))) +    print(("\n".join(map(str, anss)))) -dfs(0, -1, 0) -# print(colors) -anss = [] -for A, B in edges: -    anss.append(colors[(A, B)]) -print((max(colors.values()))) -print(("\n".join(map(str, anss)))) +solve()