Buggy python submission (verdict: Runtime Error):
import sys
from math import gcd
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        repn[u - 1].append((v - 1, w))
        repn[v - 1].append((u - 1, w))
    
    """
    Greedyに隣接する頂点ごとに色を塗っていけばよい
    """

    color = [-1] * N
    color[0] = 0
    q = [0]
    while q:
        v = q.pop()
        for u, w in repn[v]:
            if color[u] != -1:
                continue
            if w % 2 == 0:
                color[u] = color[v]
            else:
                color[u] = (1 + color[v]) % 2
            q.append(u)
    for ans in color:
        print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        repn[u - 1].append((v - 1, w))
        repn[v - 1].append((u - 1, w))
    
    """
    Greedyに隣接する頂点ごとに色を塗っていけばよい
    """

    color = [-1] * N
    color[0] = 0
    q = [0]
    while q:
        v = q.pop()
        for u, w in repn[v]:
            if color[u] != -1:
                continue
            if w % 2 == 0:
                color[u] = color[v]
            else:
                color[u] = (1 + color[v]) % 2
            q.append(u)
    for ans in color:
        print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = ['NIL' for i in range(N+1)]
appeared_num = []
 
if N == 1:
    print(1)
else:
 
    #1回目
    line = list(map(int, input().split()))
    appeared_num += [line[0], line[1]]
    if line[2] % 2 == 0:
        ans[line[0]] = 1
        ans[line[1]] = 1
    else:
        ans[line[0]] = 1
        ans[line[1]] = 0
 
    #2回目以降
    remain = []
    for i in range(N-2):
        line = list(map(int, input().split()))
        length = line[2] % 2
        if line[0] in appeared_num:
            if ans[line[0]] == 1:
                ans[line[1]] = (1 + length) % 2
            else:
                ans[line[1]] = length
            appeared_num += [line[1]]
 
 
        elif line[1] in appeared_num:
            if ans[line[1]] == 1:
                ans[line[0]] = (1 + length) % 2
            else:
                ans[line[0]] = length
                appeared_num += [line[0]]
 
        else:
            remain += line
 
    #2周目以降
    while len(remain) != 0:
        l = len(remain)
        for i in range(l):
            line = remain[i]
            length = line[2] % 2
            if line[0] in appeared_num:
                if ans[line[0]] == 1:
                    ans[line[1]] = (1 + length) % 2
                else:
                    ans[line[1]] = length
                appeared_num += [line[1]]
                remain.pop(i)
 
 
            elif line[1] in appeared_num:
                if ans[line[1]] == 1:
                    ans[line[0]] = (1 + length) % 2
                else:
                    ans[line[0]] = length
                    appeared_num += [line[0]]
                remain.pop(i)
 
            else:
                pass
 
    Ans = ans[1:]
    for i in range(N):
        print(Ans[i])

Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        repn[u - 1].append((v - 1, w))
        repn[v - 1].append((u - 1, w))
    
    """
    Greedyに隣接する頂点ごとに色を塗っていけばよい
    """

    color = [-1] * N
    color[0] = 0
    q = [0]
    while q:
        v = q.pop()
        for u, w in repn[v]:
            if color[u] != -1:
                continue
            if w % 2 == 0:
                color[u] = color[v]
            else:
                color[u] = (1 + color[v]) % 2
            q.append(u)
    for ans in color:
        print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = ['NIL' for i in range(N+1)]
appeared_num = []

if N == 1:
    print(1)
else:

    #1回目
    line = list(map(int, input().split()))
    appeared_num += [line[0], line[1]]
    if line[2] % 2 == 0:
        ans[line[0]] = 1
        ans[line[1]] = 1
    else:
        ans[line[0]] = 1
        ans[line[1]] = 0

    #2回目以降
    remain = []
    for i in range(N-2):
        line = list(map(int, input().split()))
        length = line[2] % 2
        if line[0] in appeared_num:
            if ans[line[0]] == 1:
                ans[line[1]] = (1 + length) % 2
            else:
                ans[line[1]] = length
            appeared_num += [line[1]]


        elif line[1] in appeared_num:
            if ans[line[1]] == 1:
                ans[line[0]] = (1 + length) % 2
            else:
                ans[line[0]] = length
                appeared_num += [line[0]]

        else:
            remain += line

    #2周目以降
    while len(remain) != 0:
        l = len(remain)
        for i in range(l):
            line = remain[i]
            length = line[2] % 2
            if line[0] in appeared_num:
                if ans[line[0]] == 1:
                    ans[line[1]] = (1 + length) % 2
                else:
                    ans[line[1]] = length
                appeared_num += [line[1]]
                remain.pop(i)


            elif line[1] in appeared_num:
                if ans[line[1]] == 1:
                    ans[line[0]] = (1 + length) % 2
                else:
                    ans[line[0]] = length
                    appeared_num += [line[0]]
                remain.pop(i)

            else:
                pass

    Ans = ans[1:]
    for i in range(N):
        print(Ans[i])

Fixed submission:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    repn = [[] for _ in range(N)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        repn[u - 1].append((v - 1, w))
        repn[v - 1].append((u - 1, w))
    
    """
    Greedyに隣接する頂点ごとに色を塗っていけばよい
    """

    color = [-1] * N
    color[0] = 0
    q = [0]
    while q:
        v = q.pop()
        for u, w in repn[v]:
            if color[u] != -1:
                continue
            if w % 2 == 0:
                color[u] = color[v]
            else:
                color[u] = (1 + color[v]) % 2
            q.append(u)
    for ans in color:
        print(ans)


if __name__ == "__main__":
    main()