Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
 
n = int(input())
node_list = []
nodes = [[] for _ in range(n)]
edges = dict()
for _ in range(n - 1):
	a, b = map(int, input().split())
	node_list.append((a - 1, b - 1))
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
	edges[(a - 1, b - 1)] = 0
 
used_colors = [[] for _ in range(n)]
used = [False] * n
que = deque()
que.append(0)
while len(que) > 0:
	ni = que.pop()
	for node in nodes[ni]:
		[a, b] = sorted([ni, node])
		if edges[(a, b)] == 0:
			for color in range(1, n):
				if not color in used_colors[a] and not used_colors[b]:
					break
			edges[(a, b)] = color
			used_colors[a].append(color)
			used_colors[b].append(color)
		if not used[node]:
			que.append(node)
 
	used[ni] = True
 
print(max(edges.values()))
for node in node_list:
	print(edges[node])

Fixed submission:
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])

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

n = int(input())
node_list = []
nodes = [[] for _ in range(n)]
edges = dict()
for _ in range(n - 1):
	a, b = map(int, input().split())
	node_list.append((a - 1, b - 1))
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
	edges[(a - 1, b - 1)] = 0

used = [False] * n
que = deque()
que.append(0)
while len(que) > 0:
	ni = que.pop()
	if used[ni]:
		continue
	used_colors = [edges[tuple(sorted((ni, e)))] for e in nodes[ni]]
	for node in nodes[ni]:
		[a, b] = sorted([ni, node])
		if edges[(a, b)] == 0:
			for color in range(1, n):
				if not color in used_colors:
					break
			# print((a, b), color)
			edges[(a, b)] = color
			used_colors.append(color)
		que.append(node)

	used[ni] = True

print(max(edges.values()))
for node in node_list:
	print(edges[node])


Fixed submission:
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

n = int(input())
node_list = []
nodes = [[] for _ in range(n)]
edges = dict()
for _ in range(n - 1):
	a, b = map(int, input().split())
	node_list.append((a - 1, b - 1))
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
	edges[(a - 1, b - 1)] = 0

used = [False] * n
que = deque()
que.append(0)
while len(que) > 0:
	ni = que.pop()
	if used[ni]:
		continue
	used_colors = [edges[tuple(sorted((ni, e)))] for e in nodes[ni]]
	unused = deque([c for c in range(n, 0, -1) if not c in used_colors])
	for node in nodes[ni]:
		[a, b] = sorted([ni, node])
		if edges[(a, b)] == 0:
			edges[(a, b)] = unused.pop()
		que.append(node)

	used[ni] = True

print(max(edges.values()))
for node in node_list:
	print(edges[node])


Fixed submission:
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])

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

n = int(input())
node_list = []
nodes = [[] for _ in range(n)]
edges = dict()
for _ in range(n - 1):
	a, b = map(int, input().split())
	node_list.append((a - 1, b - 1))
	nodes[a - 1].append(b - 1)
	nodes[b - 1].append(a - 1)
	edges[(a - 1, b - 1)] = 0

used = [False] * n
que = deque()
que.append(0)
while len(que) > 0:
	ni = que.pop()
	if used[ni]:
		continue
	used_colors = [edges[tuple(sorted((ni, e)))] for e in nodes[ni]]
	unused = deque([c for c in range(n, 0, -1) if not c in used_colors])
	for node in nodes[ni]:
		[a, b] = sorted([ni, node])
		if edges[(a, b)] == 0:
			# print((a, b), unused)
			edges[(a, b)] = unused.pop()
			# print(edges[(a, b)])
		que.append(node)

	used[ni] = True

print(max(edges.values()))
for node in node_list:
	print(edges[node])


Fixed submission:
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])

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

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

used = [False] * n
que = deque()
que.append(0)
while len(que) > 0:
	ni = que.pop()
	if used[ni]:
		continue
	color = 1
	used_colors = []
	unused = []
	for e in nodes[ni]:
		[a, b] = sorted([e, ni])
		used_colors.append(colors[edges.index((a, b))])
	unused = [c for c in range(1, n + 1) if not c in used_colors]
	for node in nodes[ni]:
		[a, b] = sorted([ni, node])
		# print(a, b)
		ci = edges.index((a, b))
		if colors[ci] == 0:
			# print(ni, unused)
			color = min(unused)
			colors[ci] = color
			unused = unused[1:]
		que.append(node)

	used[ni] = True

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

Fixed submission:
from collections import deque

n = int(input())
nodes = [[] for _ in range(n)]
node_list = []
for _ in range(n - 1):
	a, b = map(int, input().split())
	nodes[a - 1].append(b - 1)
	node_list.append(b - 1)
 
que = deque([0])
ans = [0] * n
while len(que) > 0:
	ni = que.pop()
	color = 1
	for node in nodes[ni]:
		if color == ans[ni]:
			color += 1
		ans[node] = color
		color += 1
		que.append(node)
 
print(max(ans))
for node in node_list:
	print(ans[node])