import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a, b = [int(_) - 1 for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
ans = [0] * (N - 1)
colors_num = max([len(_) for _ in edge])
colors = list(range(colors_num))


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = filter(lambda c: c[0] != pv, edge[v])
    for ((cv, ci), color) in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)

de11ca51b02387535d86710818a91a94b18f9eb6
<mask token>

<mask token>
sys.setrecursionlimit(10 ** 7)
<mask token>
for i in range(N - 1):
    a, b = [(int(_) - 1) for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
<mask token>


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = filter(lambda c: c[0] != pv, edge[v])
    for (cv, ci), color in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)

<mask token>
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = [(int(_) - 1) for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
ans = [0] * (N - 1)
colors_num = max([len(_) for _ in edge])
colors = list(range(colors_num))


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = filter(lambda c: c[0] != pv, edge[v])
    for (cv, ci), color in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)

import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = [(int(_) - 1) for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
ans = [0] * (N - 1)
colors_num = max([len(_) for _ in edge])
colors = list(range(colors_num))


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = filter(lambda c: c[0] != pv, edge[v])
    for (cv, ci), color in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)

import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a, b = [int(_) - 1 for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
ans = [0] * (N - 1)
colors_num = max([len(_) for _ in edge])
colors = list(range(colors_num))


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = filter(lambda c: c[0] != pv, edge[v])
    for ((cv, ci), color) in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)
