Problem p02850 (python)

Fixed submission:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
sys.setrecursionlimit(n * 10)
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    if node > next_node:
        edge_color_hash[str(next_node) + " " + str(node)] = color
    else:
        edge_color_hash[str(node) + " " + str(next_node)] = color
    new_color = 1
    max_color = color
    if next_node in node_hash_list:
        for new_next_node in node_hash_list[next_node]:
            if color == new_color:
                new_color += 1
            if max_color < new_color:
                max_color = new_color
            temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
            new_color += 1
            if max_color < temp_color:
                max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    node_hash_list[a].append(b)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    new_color = 1
    max_color = color
    if next_node in node_hash_list:
        for new_next_node in node_hash_list[next_node]:
            if color == new_color:
                new_color += 1
            if max_color < new_color:
                max_color = new_color
            temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
            new_color += 1
            if max_color < temp_color:
                max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    node_hash_list[a].append(b)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    node_hash_list[a].append(b)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])

Buggy submission (verdict: Runtime Error):
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def check(node_hash_list, edge_color_hash, next_node, node, color):
    edge_color_hash[str(node) + " " + str(next_node)] = color
    edge_color_hash[str(next_node) + " " + str(node)] = color
    new_color = 1
    max_color = color
    for new_next_node in node_hash_list[next_node]:
        if new_next_node == node:
            continue
        if color == new_color:
            new_color += 1
        if max_color < new_color:
            max_color = new_color
        temp_color = check(node_hash_list, edge_color_hash, new_next_node, next_node, new_color)
        new_color += 1
        if max_color < temp_color:
            max_color = temp_color
    return max_color
n = int(input())
node_hash_list = {}
print_list = []
for i in range(1, n):
    input_string = input()
    print_list.append(input_string)
    a, b = map(int, input_string.split())
    if a not in node_hash_list:
        node_hash_list[a] = []
    if b not in node_hash_list:
        node_hash_list[b] = []
    node_hash_list[a].append(b)
    node_hash_list[b].append(a)
edge_color_hash = {}
node = 1
color = 0
max_color = 1
for next_node in node_hash_list[node]:
    color += 1
    if max_color < color:
        max_color = color
    temp_color = check(node_hash_list, edge_color_hash, next_node, node, color)
    if max_color < temp_color:
        max_color = temp_color

print(max_color)
for key in print_list:
    print(edge_color_hash[key])