from collections import defaultdict

N = int(input())

tree = [[] for i in range(N)]  # 入力で与えられる木: [[to, 辺のindex],]

degrees = defaultdict(int)  # 各頂点の次数を記録



for i in range(N - 1):

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

    a, b = a - 1, b - 1

    tree[a].append([b, i])

    tree[b].append([a, i])

    degrees[a] += 1

    degrees[b] += 1





# 最大次数色使えば必ず塗り分けられる

ans_K = max(degrees.values())

ans_c = [-1] * (N - 1)





# [現在見ている頂点, 直前を何色で塗ったか]

stack = [[0, -1]]

visited = [False] * N

while stack:

    fr, pre_color = stack.pop()

    visited[fr] = True

    painting = 1  # これから何色で塗ろうとするか



    for to, index in tree[fr]:

        if visited[to]:

            continue



        if painting == pre_color:

            painting += 1



        ans_c[index] = painting

        stack.append([to, painting])



        # 塗ったら違う色に変える

        painting += 1





print(ans_K)

print(*ans_c, sep='\n')

N = int(input())

T = [[] for i in range(N)]

for i in range(N - 1):

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

    a, b = a - 1, b - 1



    # 辺のindexを持っておく

    T[a].append([b, i])

    T[b].append([a, i])





stack = [[0, 0]]  # [次の頂点番号, 親に続く辺の色]

visited = [0] * N

colors = [0] * (N - 1)

while stack:

    n, parent_color = stack.pop()

    visited[n] = 1

    color = 1



    for to, i in T[n]:

        if visited[to]:

            continue



        if color == parent_color:

            color += 1



        colors[i] = color

        stack.append([to, color])



        color += 1





print(len(set(colors)))

print(*colors, sep='\n')









from collections import defaultdict

N = int(input())
tree = [[] for i in range(N)]  # 入力で与えられる木: [[to, 辺のindex],]
degrees = defaultdict(int)  # 各頂点の次数を記録
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    tree[a].append([b, i])
    tree[b].append([a, i])
    degrees[a] += 1
    degrees[b] += 1
# 最大次数色使えば必ず塗り分けられる
ans_K = max(degrees.values())
ans_c = [-1] * (N - 1)
# [現在見ている頂点, 直前を何色で塗ったか]
stack = [[0, -1]]
visited = [False] * N
while stack:
    fr, pre_color = stack.pop()
    visited[fr] = True
    painting = 1  # これから何色で塗ろうとするか
    for to, index in tree[fr]:
        if visited[to]:
            continue
        if painting == pre_color:
            painting += 1
        ans_c[index] = painting
        stack.append([to, painting])
        # 塗ったら違う色に変える
        painting += 1
print(ans_K)
print(*ans_c, sep="\n")

N = int(input())
T = [[] for i in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    # 辺のindexを持っておく
    T[a].append([b, i])
    T[b].append([a, i])
stack = [[0, 0]]  # [次の頂点番号, 親に続く辺の色]
visited = [0] * N
colors = [0] * (N - 1)
while stack:
    n, parent_color = stack.pop()
    visited[n] = 1
    color = 1
    for to, i in T[n]:
        if visited[to]:
            continue
        if color == parent_color:
            color += 1
        colors[i] = color
        stack.append([to, color])
        color += 1
print(len(set(colors)))
print(*colors, sep="\n")

-from collections import defaultdict - -tree = [[] for i in range(N)]  # 入力で与えられる木: [[to, 辺のindex],] -degrees = defaultdict(int)  # 各頂点の次数を記録 +T = [[] for i in range(N)] -    tree[a].append([b, i]) -    tree[b].append([a, i]) -    degrees[a] += 1 -    degrees[b] += 1 -# 最大次数色使えば必ず塗り分けられる -ans_K = max(degrees.values()) -ans_c = [-1] * (N - 1) -# [現在見ている頂点, 直前を何色で塗ったか] -stack = [[0, -1]] -visited = [False] * N +    # 辺のindexを持っておく +    T[a].append([b, i]) +    T[b].append([a, i]) +stack = [[0, 0]]  # [次の頂点番号, 親に続く辺の色] +visited = [0] * N +colors = [0] * (N - 1) -    fr, pre_color = stack.pop() -    visited[fr] = True -    painting = 1  # これから何色で塗ろうとするか -    for to, index in tree[fr]: +    n, parent_color = stack.pop() +    visited[n] = 1 +    color = 1 +    for to, i in T[n]: -        if painting == pre_color: -            painting += 1 -        ans_c[index] = painting -        stack.append([to, painting]) -        # 塗ったら違う色に変える -        painting += 1 -print(ans_K) -print(*ans_c, sep="\n") +        if color == parent_color: +            color += 1 +        colors[i] = color +        stack.append([to, color]) +        color += 1 +print(len(set(colors))) +print(*colors, sep="\n")