from collections import deque



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



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



memo = {}

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

    E[a].append(b)

    E[b].append(a)

    memo[(a, b)] = i

    memo[(b, a)] = i



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



A = [0] * (N - 1)



cand = {i for i in range(1, K + 1)}



visited = [False] * (N + 1)



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

visited[1] = True

while Q:

    p, v = Q.popleft()

    c = 0

    for u in E[v]:

        if visited[u]:

            continue

        visited[u] = True

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

        Q.append((c, u))

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



print(K)

for a in A:

    print(a)

from collections import deque



def main():

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



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

    I = []

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

        E[a].append(b)

        I.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)))

    for i in I:

        print((C[i]))



main()
from collections import deque

N, *AB = list(map(int, open(0).read().split()))
E = [[] for _ in range(N + 1)]
memo = {}
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a].append(b)
    E[b].append(a)
    memo[(a, b)] = i
    memo[(b, a)] = i
K = max(len(e) for e in E)
A = [0] * (N - 1)
cand = {i for i in range(1, K + 1)}
visited = [False] * (N + 1)
Q = deque([(-1, 1)])
visited[1] = True
while Q:
    p, v = Q.popleft()
    c = 0
    for u in E[v]:
        if visited[u]:
            continue
        visited[u] = True
        c += 1 + (c + 1 == p)
        Q.append((c, u))
        A[memo[(v, u)]] = c
print(K)
for a in A:
    print(a)

from collections import deque


def main():
    N, *AB = list(map(int, open(0).read().split()))
    E = [[] for _ in range(N + 1)]
    I = []
    for a, b in zip(*[iter(AB)] * 2):
        E[a].append(b)
        I.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)))
    for i in I:
        print((C[i]))


main()

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