Buggy python submission (verdict: Time Limit Exceeded):
#ABC126D-EvenRelation.py

import sys
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [list(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
    distanceList = [0] + [-1]*(N-1)

    while True:
        s = len(UVW)
        if s == 0:
            break
        for i in range(s):
            u, v, w = UVW[i]
            if distanceList[u-1] != -1:
                if distanceList[v-1] == -1:
                    distanceList[v-1] = w + distanceList[u-1]
                UVW.pop(i)
                break
            elif distanceList[v-1] != -1:
                if distanceList[u-1] == -1:
                    distanceList[u-1] = w + distanceList[v-1]
                UVW.pop(i)
                break

    for d in distanceList:
        if d % 2 == 0:
            print(0)
        else:
            print(1)



if __name__ == "__main__":
    main()


Fixed submission:
#ABC126D-EvenRelation.py

import sys
import collections
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = list(map(int, sys.stdin.readline().split()))
        UVW[u-1].append([v,w])
        UVW[v-1].append([u,w])
    answerList = [0] + [-1]*(N-1)
    edge = collections.deque([(1,0)])

    while edge:
        u, w1 = edge.pop()
        for v, w2 in UVW[u-1]:
            if answerList[v-1] == -1:
                answerList[v-1] = (w1 + w2) % 2
                edge.append((v,w1+w2))

    for answer in answerList:
        print(answer)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#ABC126D-EvenRelation.py

import sys
import numpy as np

def main():
    #buffer = sys.stdin.buffer
    N = int(sys.stdin.readline())
    #UVW =  np.frombuffer(buffer.read((N-1)*4), dtype="b")
    #UVW = UVW.reshape((N-1,4))[:,:-1]
    UVW = [list(map(int, sys.stdin.readline().split())) for _ in range(N-1)]
    distanceList = [0]*N
    connectSet = {1}


    while True:
        s = len(UVW)
        if s == 0:
            break
        for i in range(s):
            u = UVW[i][0]
            v = UVW[i][1]
            w = UVW[i][2]
            if u in connectSet:
                if distanceList[v-1] == 0:
                    distanceList[v-1] = w + distanceList[u-1]
                    connectSet.add(v)
                UVW.pop(i)
                break
            elif v in connectSet:
                if distanceList[u-1] == 0:
                    distanceList[u-1] = w + distanceList[v-1]
                    connectSet.add(u)
                UVW.pop(i)
                break

    for d in distanceList:
        if d % 2 == 0:
            print(0)
        else:
            print(1)



if __name__ == "__main__":
    main()


Fixed submission:
#ABC126D-EvenRelation.py

import sys
import collections
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = list(map(int, sys.stdin.readline().split()))
        UVW[u-1].append([v,w])
        UVW[v-1].append([u,w])
    answerList = [0] + [-1]*(N-1)
    edge = collections.deque([(1,0)])

    while edge:
        u, w1 = edge.pop()
        for v, w2 in UVW[u-1]:
            if answerList[v-1] == -1:
                answerList[v-1] = (w1 + w2) % 2
                edge.append((v,w1+w2))

    for answer in answerList:
        print(answer)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#ABC126D-EvenRelation.py

from sys import stdin
from functools import lru_cache

input = stdin.readline

N = int(input())

UVW = []

for i in range(N-1):
    UVW.append(list(map(int, input().split())))

UVW.sort()

@lru_cache(maxsize=None)
def d(i):
    if i == 1:
        return 0
    else:
        for uvw in UVW:
            if uvw[0] == i:
                return d(uvw[1]) + uvw[2]
            elif uvw[1] == i:
                return d(uvw[0]) + uvw[2]

for i in range(N):
    if d(i+1) % 2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
#ABC126D-EvenRelation.py

import sys
import collections
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = list(map(int, sys.stdin.readline().split()))
        UVW[u-1].append([v,w])
        UVW[v-1].append([u,w])
    answerList = [0] + [-1]*(N-1)
    edge = collections.deque([(1,0)])

    while edge:
        u, w1 = edge.pop()
        for v, w2 in UVW[u-1]:
            if answerList[v-1] == -1:
                answerList[v-1] = (w1 + w2) % 2
                edge.append((v,w1+w2))

    for answer in answerList:
        print(answer)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
#ABC126D-EvenRelation.py

from sys import stdin
from functools import lru_cache

input = stdin.readline

N = int(input())

UVW = []

for i in range(N-1):
    UVW.append(list(map(int, input().split())))

UVW.sort()
print(UVW)

@lru_cache(maxsize=None)
def d(i):
    if i == 1:
        return 0
    else:
        for uvw in UVW:
            if uvw[1] == i:
                return d(uvw[0]) + uvw[2]

for _ in range(N):
    if d(i) % 2 == 0:
        print(0)
    else:
        print(1)


Fixed submission:
#ABC126D-EvenRelation.py

import sys
import collections
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = list(map(int, sys.stdin.readline().split()))
        UVW[u-1].append([v,w])
        UVW[v-1].append([u,w])
    answerList = [0] + [-1]*(N-1)
    edge = collections.deque([(1,0)])

    while edge:
        u, w1 = edge.pop()
        for v, w2 in UVW[u-1]:
            if answerList[v-1] == -1:
                answerList[v-1] = (w1 + w2) % 2
                edge.append((v,w1+w2))

    for answer in answerList:
        print(answer)



if __name__ == "__main__":
    main()