Problem p03044 (python)

Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

class Node:
    def __init__(self):
        self.color = 0
        self.check = False
        self.link = []

def main():
    N = int(input())

    nodes = [Node() for i in range(N)]
    
    for i in range(N-1):
        u, v, w = map(int, input().split())
        nodes[u-1].link.append((nodes[v-1], w&1))
        nodes[v-1].link.append((nodes[u-1], w&1))
    
    q = deque()
    q.append((nodes[0], 1))
    while len(q) > 0:
        node, color = q.popleft()
        node.color = color
        node.check = True
        for nex, weight in node.link:
            if not nex.check:
                if weight == 0:
                    q.append((nex, color))
                else:
                    q.append((nex, -color))
    
    for i in range(N):
        print((nodes[i].color + 1) // 2)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
class Node:
    def __init__(self, val):
        self.num = val
        self.nodes = []
        self.distance = []

def set_color(node, color):
    if color_list[node.num] == None:
        color_list[node.num] = color
        if len(node.nodes) > 0:
            for child, dist in zip(node.nodes, node.distance):
                if child != node:
                    if dist == 0:
                        set_color(child, color)
                    else:
                        set_color(child, not color)

N= int(input())

node_list = [Node(i) for i in range(N)]
color_list = [None for i in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    x = node_list[u-1]
    y = node_list[v-1]
    w = w % 2
    x.nodes.append(y)
    x.distance.append(w)
    y.nodes.append(x)
    y.distance.append(w)

set_color(node_list[0], True)

for i in color_list:
    if i:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
class Node:
    def __init__(self, val):
        self.num = val
        self.nodes = []
        self.distance = []

def set_color(node, color):
    if color_list[node.num] == None:
        color_list[node.num] = color
        if len(node.child) > 0:
            for child, dist in zip(node.nodes, node.distance):
                if child != node:
                    if dist == 0:
                        set_color(child, color)
                    else:
                        set_color(child, not color)

N= int(input())

node_list = [Node(i) for i in range(N)]
color_list = [None for i in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    x = node_list[u-1]
    y = node_list[v-1]
    w = w % 2
    x.nodes.append(y)
    x.distance.append(w)
    y.nodes.append(x)
    y.distance.append(w)

set_color(node_list[0], True)

for i in color_list:
    if i:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
class Node:
    def __init__(self, val):
        self.num = val
        self.nodes = []
        self.distance = []

def set_color(node, color):
    if color_list[node.num] == None:
        color_list[node.num] = color
        for child, dist in zip(node.nodes, node.distance):
            if child != node:
                if dist == 0:
                    set_color(child, color)
                else:
                    set_color(child, not color)

N= int(input())

node_list = [Node(i) for i in range(N)]
color_list = [None for i in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    x = node_list[u-1]
    y = node_list[v-1]
    w = w % 2
    x.nodes.append(y)
    x.distance.append(w)
    y.nodes.append(x)
    y.distance.append(w)

set_color(node_list[0], True)

for i in color_list:
    if i:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
import numpy as np

class Node:
    def __init__(self, val):
        self.num = val
        self.nodes = []
        self.distance = []

def set_color(node, color):
    if color_list[node.num] == None:
        color_list[node.num] = color
        for child, dist in zip(node.nodes, node.distance):
            if child != node:
                if dist == 0:
                    set_color(child, color)
                else:
                    set_color(child, not color)

N= int(input())

node_list = [Node(i) for i in range(N)]
color_list = np.array([None for i in range(N)])

for i in range(N-1):
    u, v, w = map(int, input().split())
    x = node_list[u-1]
    y = node_list[v-1]
    w = w % 2
    x.nodes.append(y)
    x.distance.append(w)
    y.nodes.append(x)
    y.distance.append(w)

set_color(node_list[0], True)

for i in np.array(color_list, dtype=int):
    print(i)