from collections import deque



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



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

memo = {}

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

    E[a].add(b)

    E[b].add(a)

    memo[(a, b)] = i

    memo[(b, a)] = i



K = max(len(e) for e in E)



A = [0] * (N - 1)



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

while Q:

    p, v = Q.popleft()

    C = (c for c in range(1, K + 1) if c != p)

    for u in E[v]:

        E[u].remove(v)

        c = next(C)

        Q.append((c, u))

        A[memo[(v, u)]] = c



print(K)

for a in A:

    print(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))



K = max(len(e) for e in E)

A = [0] * (N - 1)

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

while Q:

    p, v = Q.popleft()

    C = (c for c in range(1, K + 1) if c != p)

    for u, i in E[v]:

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

        c = next(C)

        Q.append((c, u))

        A[i] = c



print(K)

for a in A:

    print(a)

from collections import deque

N, *AB = list(map(int, open(0).read().split()))
E = [set() for _ in range(N + 1)]
memo = {}
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a].add(b)
    E[b].add(a)
    memo[(a, b)] = i
    memo[(b, a)] = i
K = max(len(e) for e in E)
A = [0] * (N - 1)
Q = deque([(-1, 1)])
while Q:
    p, v = Q.popleft()
    C = (c for c in range(1, K + 1) if c != p)
    for u in E[v]:
        E[u].remove(v)
        c = next(C)
        Q.append((c, u))
        A[memo[(v, u)]] = c
print(K)
for a in A:
    print(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))
K = max(len(e) for e in E)
A = [0] * (N - 1)
Q = deque([(-1, 1)])
while Q:
    p, v = Q.popleft()
    C = (c for c in range(1, K + 1) if c != p)
    for u, i in E[v]:
        E[u].remove((v, i))
        c = next(C)
        Q.append((c, u))
        A[i] = c
print(K)
for a in A:
    print(a)

-memo = {} -    E[a].add(b) -    E[b].add(a) -    memo[(a, b)] = i -    memo[(b, a)] = i +    E[a].add((b, i)) +    E[b].add((a, i)) -    for u in E[v]: -        E[u].remove(v) +    for u, i in E[v]: +        E[u].remove((v, i)) -        A[memo[(v, u)]] = c +        A[i] = c