import sys

input = sys.stdin.readline



N = int(eval(input()))

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

Ed = {}

for i in range(N-1):

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

    graph[a-1].append(b-1)

    graph[b-1].append(a-1)

    Ed[(a-1)*N+b-1] = i

    Ed[(b-1)*N+a-1] = i



q = [0]

checked = [False]*N

checked[0] = True



V_color = [None]*N

V_color[0] = 0



ans = [None]*(N-1)

while q:

    qq = []

    for p in q:

        c = V_color[p]

        t = 1

        for np in graph[p]:

            if not checked[np]:

                checked[np] = True

                qq.append(np)

                ind = Ed[p*N+np]

                if t == c:

                    t += 1

                ans[ind] = t

                V_color[np] = t

                t += 1

    q = qq



print((max(ans)))

for a in ans:

    print(a)
import sys

input = sys.stdin.readline



N = int(eval(input()))

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

Edges = []

for _ in range(N-1):

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

    graph[a-1].append(b-1)

    graph[b-1].append(a-1)

    Edges.append((a-1, b-1))



Col = 0

for n in range(N):

    Col = max(Col, len(graph[n]))



Color = dict()

checked = [-1]*N

q = [0]

checked[0] = Col+1

while q:

    qq = []

    for p in q:

        c = checked[p]

        t = 0

        for np in graph[p]:

            if checked[np] == -1:

                if t == c:

                    t += 1

                checked[np] = t

                Color[(p, np)] = t

                Color[(np, p)] = t

                t += 1

                qq.append(np)

    q = qq



print(Col)

for a, b in Edges:

    print((Color[(a, b)]+1))
import sys

input = sys.stdin.readline
N = int(eval(input()))
graph = [[] for _ in range(N)]
Ed = {}
for i in range(N - 1):
    a, b = list(map(int, input().split()))
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
    Ed[(a - 1) * N + b - 1] = i
    Ed[(b - 1) * N + a - 1] = i
q = [0]
checked = [False] * N
checked[0] = True
V_color = [None] * N
V_color[0] = 0
ans = [None] * (N - 1)
while q:
    qq = []
    for p in q:
        c = V_color[p]
        t = 1
        for np in graph[p]:
            if not checked[np]:
                checked[np] = True
                qq.append(np)
                ind = Ed[p * N + np]
                if t == c:
                    t += 1
                ans[ind] = t
                V_color[np] = t
                t += 1
    q = qq
print((max(ans)))
for a in ans:
    print(a)

import sys

input = sys.stdin.readline
N = int(eval(input()))
graph = [[] for _ in range(N)]
Edges = []
for _ in range(N - 1):
    a, b = list(map(int, input().split()))
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
    Edges.append((a - 1, b - 1))
Col = 0
for n in range(N):
    Col = max(Col, len(graph[n]))
Color = dict()
checked = [-1] * N
q = [0]
checked[0] = Col + 1
while q:
    qq = []
    for p in q:
        c = checked[p]
        t = 0
        for np in graph[p]:
            if checked[np] == -1:
                if t == c:
                    t += 1
                checked[np] = t
                Color[(p, np)] = t
                Color[(np, p)] = t
                t += 1
                qq.append(np)
    q = qq
print(Col)
for a, b in Edges:
    print((Color[(a, b)] + 1))

-Ed = {} -for i in range(N - 1): +Edges = [] +for _ in range(N - 1): -    Ed[(a - 1) * N + b - 1] = i -    Ed[(b - 1) * N + a - 1] = i +    Edges.append((a - 1, b - 1)) +Col = 0 +for n in range(N): +    Col = max(Col, len(graph[n])) +Color = dict() +checked = [-1] * N -checked = [False] * N -checked[0] = True -V_color = [None] * N -V_color[0] = 0 -ans = [None] * (N - 1) +checked[0] = Col + 1 -        c = V_color[p] -        t = 1 +        c = checked[p] +        t = 0 -            if not checked[np]: -                checked[np] = True -                qq.append(np) -                ind = Ed[p * N + np] +            if checked[np] == -1: -                ans[ind] = t -                V_color[np] = t +                checked[np] = t +                Color[(p, np)] = t +                Color[(np, p)] = t +                qq.append(np) -print((max(ans))) -for a in ans: -    print(a) +print(Col) +for a, b in Edges: +    print((Color[(a, b)] + 1))