Buggy python submission (verdict: Runtime Error):
n = int(input())
tree = [0]*n
input_list = [0]*n

for i in range(n-1):
    a, b = map(int, input().split())
    input_list[i] = [a, b]
    tree[a-1] = tree[a-1] + 1
    tree[b-1] = tree[b-1] + 1

ans = max(tree)
print(ans)

key = [int(i) for i in range(1, ans+1)]
keyofkey = [[] for i in range(n)]
key = set(key)

for i in range(n-1):
    a, b = input_list[i][0], input_list[i][1]
    key_list = list(key - (set(keyofkey[a-1]) | set(keyofkey[b-1])))
    p = key_list[0]
    keyofkey[a-1].append(p)
    keyofkey[b-1].append(p)
    print(p)

Fixed submission:
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [0]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            
    
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import heapq
n = int(input())
tree = [0]*n
input_list = [0]*n
 
for i in range(n-1):
    a, b = map(int, input().split())
    input_list[i] = [a, b]
    tree[a-1] = tree[a-1] + 1
    tree[b-1] = tree[b-1] + 1

ans = max(tree)
print(ans)

keyofkey = [[int(i) for i in range(1, ans+1)] for i in range(n)]

for i in range(n-1):
    a, b = input_list[i][0], input_list[i][1]
    key_list = list(set(keyofkey[a-1]) & set(keyofkey[b-1]))
    p = key_list[0]
    keyofkey[a-1].remove(p)
    keyofkey[b-1].remove(p)
    print(p)

Fixed submission:
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [0]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            
    
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
tree = [[0]*n for i in range(n)]
input_list = [0]*n
   
for i in range(n-1):
    a, b = map(int, input().split())
    input_list[i] = [a, b]
    tree[a-1][b-1] = -1
    tree[b-1][a-1] = -1

ans = 0
for i in range(n):
    key = tree[i].count(-1)
    if key > ans:
        ans = key
print(ans)

keyofkey = [[int(i) for i in range(1, ans+1)] for i in range(n)]

for i in range(n-1):
    a, b = input_list[i][0], input_list[i][1]
    key_list = list(set(keyofkey[a-1]) & set(keyofkey[b-1]))
    p = key_list[0]
    keyofkey[a-1].remove(p)
    keyofkey[b-1].remove(p)
    print(p)

Fixed submission:
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n = int(input())
    
    node = [0]*(n-1)
    next_node = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        node[i] = (a-1, b-1)
        next_node[a-1].append(b-1)
        next_node[b-1].append(a-1)
    
    ans = 0
    for i in range(n):
        if ans < len(next_node[i]):
            ans = len(next_node[i])
    print(ans)
    
    not_yet = deque([])
    already = [False]*n
    parent = [0]*n
    ans_list = dict()
    k = 1
    
    already[0] = True
    for value in next_node[0]:
        not_yet.append(value)
        ans_list[(0, value)] = k
        parent[value] = k
        already[value] = True
        k += 1
    
    
    while not_yet:
        k = 1
        key = not_yet.popleft()
        for value in next_node[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            if k == parent[key]:
                k += 1
            parent[value] = k
            p, q = min([key, value]), max([key, value])
            ans_list[(p, q)] = k
            k += 1
            
    
    for value in node:
        print(ans_list[value])


if __name__ == "__main__":
    main()