Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w])
     x[v-1].append([u-1,w])



ret = {}
done = []

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if neigh in done:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        if neigh[0] not in done:
            queue.append(neigh[0])
    done.append(curr)


for i in range(N):
    print(ret[i])


Fixed submission:
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w%2])
     x[v-1].append([u-1,w%2])



ret = {}
done = [0 for x in range(N)]

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if done[neigh[0]] == 1:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        queue.append(neigh[0])
    done[curr] = 1


for i in range(N):
    print(ret[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w])
     x[v-1].append([u-1,w])



ret = {}
done = []

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        if neigh[0] not in done:
            queue.append(neigh[0])
    done.append(curr)


for i in range(N):
    print(ret[i])


Fixed submission:
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w%2])
     x[v-1].append([u-1,w%2])



ret = {}
done = [0 for x in range(N)]

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if done[neigh[0]] == 1:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        queue.append(neigh[0])
    done[curr] = 1


for i in range(N):
    print(ret[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().strip())
x = [[0 for x in range(N)] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1][v-1] = w
     x[v-1][u-1] = w


ret = {}
done = []

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for j in range(N):
        if x[curr][j] > 0:
            if x[curr][j] %2 == 0:
                ret[j] = ret[curr]
            else:
                ret[j] = 0 if ret[curr] == 1 else 1
            if j not in done:
                queue.append(j)
    done.append(curr)


for i in range(N):
    print(ret[i])


Fixed submission:
N = int(input().strip())
x = [[] for x in range(N)]
for i in range(N-1):
     u, v, w = list(map(int, input().split()))
     x[u-1].append([v-1, w%2])
     x[v-1].append([u-1,w%2])



ret = {}
done = [0 for x in range(N)]

queue = [0]

for i in range(N):
    curr = queue.pop()
    if curr == 0:
        ret[0] = 0

    for neigh in x[curr]:
        if done[neigh[0]] == 1:
            continue
        if neigh[1] % 2 == 0:
            ret[neigh[0]] = ret[curr]
        else:
            ret[neigh[0]] = 0 if ret[curr] == 1 else 1

        queue.append(neigh[0])
    done[curr] = 1


for i in range(N):
    print(ret[i])