Problem p03044 (python)

Fixed submission:
#!/usr/bin/env python3
import sys

class Node:
    def __init__(self):
        self.children = []
        self.color = -1
    
    def append(self,target,weight):
        self.children.append((target,weight))
        target.children.append((self,weight))
 
    def setColor(self,color):
        self.color = color
        for child in self.children:
            if child[0].color != -1:
                continue
            if child[1] % 2 == 0:
                child[0].setColor(self.color)
            else:
                child[0].setColor(0 if self.color == 1 else 1)

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    nodes = [Node() for i in range(N)]
    # print(u)
    for i in range(N-1):
        nodes[u[i]-1].append(nodes[v[i]-1],w[i])
    colorQueue = [(nodes[0],0)]
    while True:
        if len(colorQueue) == 0:
            break
        next = colorQueue.pop()
        next[0].color = next[1]
        for child in next[0].children:
            if child[0].color != -1:
                continue
            if child[1] % 2 == 0:
                colorQueue.append((child[0],next[0].color))
            else:
                colorQueue.append((child[0],0 if next[0].color == 1 else 1))

    for n in nodes:
        print(n.color)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

class Node:
    def __init__(self):
        self.children = []
        self.color = -1
    
    def append(self,target,weight):
        self.children.append((target,weight))
        target.children.append((self,weight))
 
    def setColor(self,color):
        self.color = color
        for child in self.children:
            if child[0].color != -1:
                continue
            if child[1] % 2 == 0:
                child[0].setColor(self.color)
            else:
                child[0].setColor(0 if self.color == 1 else 1)

def solve(N: int, u: "List[int]", v: "List[int]", w: "List[int]"):
    nodes = [Node() for i in range(N)]
    # print(u)
    for i in range(N-1):
        nodes[u[i]-1].append(nodes[v[i]-1],w[i])
    nodes[0].setColor(0)
    for n in nodes:
        print(n.color)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    u = [int()] * (N - 1)  # type: "List[int]"
    v = [int()] * (N - 1)  # type: "List[int]"
    w = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        u[i] = int(next(tokens))
        v[i] = int(next(tokens))
        w[i] = int(next(tokens))
    solve(N, u, v, w)

if __name__ == '__main__':
    main()