Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
sys.setrecursionlimit(n)
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    graph[a].append((b, i))
    graph[b].append((a, i))

def DFS(node, p_node=-1, p_color=-1):
    color = 1
    for c_node, edge in graph[node]:
        if c_node==p_node:
            continue
        if color==p_color:
            color += 1
        ans[edge] = color
        DFS(c_node, node, color)
        color += 1
ans = [0]*(n-1)
DFS(0)
k = max(len(i) for i in graph)
print(k)
[print(i) for i in ans]

Fixed submission:
import sys
n = int(input())
sys.setrecursionlimit(2*n)
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    graph[a].append((b, i))
    graph[b].append((a, i))

def DFS(node, p_node=-1, p_color=-1):
    color = 1
    for c_node, edge in graph[node]:
        if c_node==p_node:
            continue
        if color==p_color:
            color += 1
        ans[edge] = color
        DFS(c_node, node, color)
        color += 1
ans = [0]*(n-1)
DFS(0)
k = max(len(i) for i in graph)
print(k)
[print(i) for i in ans]

Buggy python submission (verdict: Runtime Error):
import sys
n = int(input())
sys.setrecursionlimit(n)
graph = [[] for _ in range(n)]
edge = []
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    edge.append({a,b})
    graph[a].append(b)
    graph[b].append(a)
k = max(len(i) for i in graph)

ans = [0]*(n-1)
def DFS(cur, pre=-1, p_color=-1):
    color = 1
    for i in graph[cur]:
        if i==pre:
            continue
        if color==p_color:
            color += 1
        ans[edge.index({cur, i})] = color
        DFS(i, cur, color)
        color += 1
DFS(0)
print(k)
[print(i) for i in ans]

Fixed submission:
import sys
n = int(input())
sys.setrecursionlimit(2*n)
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    graph[a].append((b, i))
    graph[b].append((a, i))

def DFS(node, p_node=-1, p_color=-1):
    color = 1
    for c_node, edge in graph[node]:
        if c_node==p_node:
            continue
        if color==p_color:
            color += 1
        ans[edge] = color
        DFS(c_node, node, color)
        color += 1
ans = [0]*(n-1)
DFS(0)
k = max(len(i) for i in graph)
print(k)
[print(i) for i in ans]

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n = int(input())
graph = [[] for _ in range(n)]
edge = []
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    edge.append({a,b})
    graph[a].append(b)
    graph[b].append(a)
k = max(len(i) for i in graph)

que = deque()
seen = [False]*n
ans = [0]*(n-1)
que.append((0, -1))
while len(que)>0:
    node, p_color = que.popleft()
    seen[node] = True
    color = 1
    for i in graph[node]:
        if seen[i]:
            continue
        if color==p_color:
            color += 1
        ans[edge.index({node,i})] = color
        que.append((i, color))
        color += 1
print(k)
[print(i) for i in ans]

Fixed submission:
import sys
n = int(input())
sys.setrecursionlimit(2*n)
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    graph[a].append((b, i))
    graph[b].append((a, i))

def DFS(node, p_node=-1, p_color=-1):
    color = 1
    for c_node, edge in graph[node]:
        if c_node==p_node:
            continue
        if color==p_color:
            color += 1
        ans[edge] = color
        DFS(c_node, node, color)
        color += 1
ans = [0]*(n-1)
DFS(0)
k = max(len(i) for i in graph)
print(k)
[print(i) for i in ans]

Buggy python submission (verdict: Runtime Error):
n = int(input())
node = [[] for _ in range(n)]
edge = []
for i in range(n-1):
    a,b = map(lambda x:int(x)-1, input().split())
    edge.append((a,b))
    node[a].append(b)
    node[b].append(a)
k = max(len(i) for i in node)
print(k)
node = [set(range(1,k+1)) for _ in range(n)]
for i,j in edge:
    tmp = (node[i]&node[j]).pop()
    node[i].remove(tmp)
    node[j].remove(tmp)
    print(tmp)

Fixed submission:
import sys
n = int(input())
sys.setrecursionlimit(2*n)
graph = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x:int(x)-1, input().split())
    graph[a].append((b, i))
    graph[b].append((a, i))

def DFS(node, p_node=-1, p_color=-1):
    color = 1
    for c_node, edge in graph[node]:
        if c_node==p_node:
            continue
        if color==p_color:
            color += 1
        ans[edge] = color
        DFS(c_node, node, color)
        color += 1
ans = [0]*(n-1)
DFS(0)
k = max(len(i) for i in graph)
print(k)
[print(i) for i in ans]