from collections import deque



N = int(eval(input()))

edge = [[] for _ 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))

ec = [0] * (N - 1)





def bfs():

    q = deque()

    q.append((0, 0))



    while len(q):

        v, pc = q.popleft()

        color = 1



        for e in edge[v]:

            if color == pc:

                color += 1



            if ec[e[1]] == 0:

                ec[e[1]] = color

                q.append((e[0], color))

                color += 1





bfs()

print((max(ec)))

for c in ec:

    print(c)

import sys

sys.setrecursionlimit(10 ** 6)





def dfs(v, c):

    nc = 0

    k = 0

    for nv, idx in edge[v]:

        if status[nv] == 0:

            nc = nc + 1 + ((nc + 1) == c)

            color[idx] = nc

            status[nv] = 1

            k = max(k, dfs(nv, nc))

    return max(nc, k)





N = int(eval(input()))

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

for idx, line in enumerate(sys.stdin.readlines()):

    a, b = [int(x) - 1 for x in line.split()]

    edge[a].append((b, idx))

    edge[b].append((a, idx))



status = [0] * N

color = [0] * (N - 1)

status[0] = 1

K = dfs(0, 0)



print(K)

for c in color:

    print(c)

from collections import deque

N = int(eval(input()))
edge = [[] for _ 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))
ec = [0] * (N - 1)


def bfs():
    q = deque()
    q.append((0, 0))
    while len(q):
        v, pc = q.popleft()
        color = 1
        for e in edge[v]:
            if color == pc:
                color += 1
            if ec[e[1]] == 0:
                ec[e[1]] = color
                q.append((e[0], color))
                color += 1


bfs()
print((max(ec)))
for c in ec:
    print(c)

import sys

sys.setrecursionlimit(10**6)


def dfs(v, c):
    nc = 0
    k = 0
    for nv, idx in edge[v]:
        if status[nv] == 0:
            nc = nc + 1 + ((nc + 1) == c)
            color[idx] = nc
            status[nv] = 1
            k = max(k, dfs(nv, nc))
    return max(nc, k)


N = int(eval(input()))
edge = [[] for _ in range(N)]
for idx, line in enumerate(sys.stdin.readlines()):
    a, b = [int(x) - 1 for x in line.split()]
    edge[a].append((b, idx))
    edge[b].append((a, idx))
status = [0] * N
color = [0] * (N - 1)
status[0] = 1
K = dfs(0, 0)
print(K)
for c in color:
    print(c)

-from collections import deque +import sys + +sys.setrecursionlimit(10**6) + + +def dfs(v, c): +    nc = 0 +    k = 0 +    for nv, idx in edge[v]: +        if status[nv] == 0: +            nc = nc + 1 + ((nc + 1) == c) +            color[idx] = nc +            status[nv] = 1 +            k = max(k, dfs(nv, nc)) +    return max(nc, k) + -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)) -ec = [0] * (N - 1) - - -def bfs(): -    q = deque() -    q.append((0, 0)) -    while len(q): -        v, pc = q.popleft() -        color = 1 -        for e in edge[v]: -            if color == pc: -                color += 1 -            if ec[e[1]] == 0: -                ec[e[1]] = color -                q.append((e[0], color)) -                color += 1 - - -bfs() -print((max(ec))) -for c in ec: +for idx, line in enumerate(sys.stdin.readlines()): +    a, b = [int(x) - 1 for x in line.split()] +    edge[a].append((b, idx)) +    edge[b].append((a, idx)) +status = [0] * N +color = [0] * (N - 1) +status[0] = 1 +K = dfs(0, 0) +print(K) +for c in color: