Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()
    cand = [i+1 for i in range(max_len)]
    current_colors = [colors[p[0]] for p in mat[current] if colors[p[0]] > 0]
    for col in current_colors:
        cand.remove(col)

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        col = cand.pop()
        colors[p[0]] = col
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)



Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = []
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.pop()
    cand = [i+1 for i in range(max_len)]
    current_colors = [colors[p[0]] for p in mat[current] if colors[p[0]] > 0]
    for col in current_colors:
        cand.remove(col)

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        col = cand.pop()
        colors[p[0]] = col
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)





Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = []
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.pop()
    cand = [i+1 for i in range(max_len)]
    current_colors = [colors[p[0]] for p in mat[current] if colors[p[0]] > 0]
    for col in current_colors:
        cand.remove(col)

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        col = cand.pop()
        colors[p[0]] = col
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)





Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N = int(input())
edge_list = [list(map(int, input().split())) for i in range(N-1)]
colors = [[0 for j in range(N)] for i in range(N)]
reached = [False for i in range(N)]
edges = [[] for j in range(N)]
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    edges[a].append(b)
    edges[b].append(a)

color_num = 0
for i in range(N):
    if len(edges[i]) > color_num:
        color_num = len(edges[i])


color_stack = deque([[]])
node_stack = deque([0])
while len(node_stack) > 0:
    current = node_stack.pop()
    reached[current] = True
    used_colors = color_stack.pop()
    nodes = edges[current]
    if (len(used_colors)) == 0:
        can_color = [i+1 for i in range(color_num)]
    else:
        can_color = [i+1 for i in range(color_num) if i != used_colors[0]-1]
    for node in nodes:
        if reached[node]:
            continue
        color = can_color.pop()
        node_stack.append(node)
        color_stack.append([color])
        colors[current][node] = color
        colors[node][current] = color

print(color_num)
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    print(colors[a][b])



Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N = int(input())
edge_list = [list(map(int, input().split())) for i in range(N-1)]
colors = [[0 for j in range(N)] for i in range(N)]
reached = [False for i in range(N)]
edges = [[] for j in range(N)]
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    edges[a].append(b)
    edges[b].append(a)

color_num = 0
for i in range(N):
    if len(edges[i]) > color_num:
        color_num = len(edges[i])


color_stack = deque([[]])
node_stack = deque([0])
while len(node_stack) > 0:
    current = node_stack.pop()
    reached[current] = True
    used_colors = color_stack.pop()
    nodes = edges[current]
    can_color = [i+1 for i in range(color_num)]
    for color in used_colors:
        can_color.remove(color)
    for node in nodes:
        if reached[node]:
            continue
        color = can_color.pop()
        node_stack.append(node)
        color_stack.append([color])
        colors[current][node] = color
        colors[node][current] = color

print(color_num)
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    print(colors[a][b])



Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
edge_list = [list(map(int, input().split())) for i in range(N-1)]
colors = [[0 for j in range(N)] for i in range(N)]
reached = [False for i in range(N)]
edges = [[] for j in range(N)]
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    edges[a].append(b)
    edges[b].append(a)

color_num = 0
for i in range(N):
    if len(edges[i]) > color_num:
        color_num = len(edges[i])


color_stack = [[]]
node_stack = [0]
while len(node_stack) > 0:
    current = node_stack.pop()
    reached[current] = True
    used_colors = color_stack.pop()
    nodes = edges[current]
    can_color = [i+1 for i in range(color_num)]
    for color in used_colors:
        can_color.remove(color)
    for node in nodes:
        if reached[node]:
            continue
        color = can_color.pop()
        node_stack.insert(0, node)
        color_stack.insert(0, [color])
        colors[current][node] = color
        colors[node][current] = color

print(color_num)
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    print(colors[a][b])



Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
edge_list = [list(map(int, input().split())) for i in range(N-1)]
colors = [[0 for j in range(N)] for i in range(N)]
reached = [False for i in range(N)]
edges = [[False for i in range(N)] for j in range(N)]
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    edges[a][b] = True
    edges[b][a] = True

color_num = 0
for i in range(N):
    if sum(edges[i]) > color_num:
        color_num = sum(edges[i])


color_stack = [[]]
node_stack = [0]
while len(node_stack) > 0:
    current = node_stack.pop()
    reached[current] = True
    used_colors = color_stack.pop()
    nodes = [i for i in range(len(edges[current])) if edges[current][i] and not reached[i]]
    can_color = [i+1 for i in range(color_num)]
    for color in used_colors:
        can_color.remove(color)
    for node in nodes:
        color = can_color.pop()
        node_stack.insert(0, node)
        color_stack.insert(0, [color])
        colors[current][node] = color
        colors[node][current] = color

print(color_num)
for edge in edge_list:
    a = edge[0] - 1
    b = edge[1] - 1
    print(colors[a][b])



Fixed submission:
from collections import deque
from functools import reduce

n = int(input())
colors = [0]*(n-1)
mat = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

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

q = deque()
max_len = reduce(lambda a, x:max(a, len(x)), mat, 0)
q.append(0)
while len(q) > 0:
    current = q.popleft()

    used_colors = set([colors[p[0]] for p in mat[current] if colors[p[0]] > 0])
    col = 1

    for p in mat[current]:
        if colors[p[0]] > 0:
            continue
        while col in used_colors:
            col += 1
        colors[p[0]] = col
        col += 1
        q.append(p[1])
print(max_len)
for col in colors:
    print(col)