from collections import deque



N, *AB = list(map(int, open(0).read().split()))



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

for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):

    E[a].add((b, i))

    E[b].add((a, i))



A = [0] * (N - 1)

Q = deque([(0, 1)])

while Q:

    p, v = Q.popleft()

    c = 0

    for u, i in E[v]:

        E[u].remove((v, i))

        c += 1 + (c + 1 == p)

        Q.append((c, u))

        A[i] = c



print((max(A), *A))
from collections import deque



N, *AB = list(map(int, open(0).read().split()))



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

for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):

    E[a].add((b, i))

    E[b].add((a, i))



A = [0] * (N - 1)

Q = deque([1])

while Q:

    p, v = divmod(Q.popleft(), N + 1)

    c = 0

    for u, i in E[v]:

        E[u].remove((v, i))

        c += 1 + (c + 1 == p)

        Q.append(c * (N + 1) + u)

        A[i] = c



print((max(A)))

print(("\n".join(map(str, A))))
from collections import deque

N, *AB = list(map(int, open(0).read().split()))
E = [set() for _ in range(N + 1)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a].add((b, i))
    E[b].add((a, i))
A = [0] * (N - 1)
Q = deque([(0, 1)])
while Q:
    p, v = Q.popleft()
    c = 0
    for u, i in E[v]:
        E[u].remove((v, i))
        c += 1 + (c + 1 == p)
        Q.append((c, u))
        A[i] = c
print((max(A), *A))

from collections import deque

N, *AB = list(map(int, open(0).read().split()))
E = [set() for _ in range(N + 1)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a].add((b, i))
    E[b].add((a, i))
A = [0] * (N - 1)
Q = deque([1])
while Q:
    p, v = divmod(Q.popleft(), N + 1)
    c = 0
    for u, i in E[v]:
        E[u].remove((v, i))
        c += 1 + (c + 1 == p)
        Q.append(c * (N + 1) + u)
        A[i] = c
print((max(A)))
print(("\n".join(map(str, A))))

-Q = deque([(0, 1)]) +Q = deque([1]) -    p, v = Q.popleft() +    p, v = divmod(Q.popleft(), N + 1) -        Q.append((c, u)) +        Q.append(c * (N + 1) + u) -print((max(A), *A)) +print((max(A))) +print(("\n".join(map(str, A))))