Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edges = []
# edges = [[] for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edges.append([u-1,v-1,w])

    # edges[u-1].append([v-1,w])
    # edges[v-1].append([u-1,w])


dist = [None]*N
dist[0] = 0
cnt = 1 # 点1個は確定済み
while cnt < N:
    for edge in edges:
        if dist[edge[0]] == None and dist[edge[1]] != None:
            dist[edge[0]] = dist[edge[1]] + edge[2]
            cnt += 1
        elif dist[edge[1]] == None and dist[edge[0]] != None:
            dist[edge[1]] = dist[edge[0]] + edge[2]
            cnt += 1

for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edges = []
# edges = [[] for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edges.append([u-1,v-1,w])

    # edges[u-1].append([v-1,w])
    # edges[v-1].append([u-1,w])


dist = [None]*N
dist[0] = 0
cnt = 0
while len(edges) > 0:
    for edge in edges:
        if dist[edge[0]] == None and dist[edge[1]] != None:
            dist[edge[0]] = dist[edge[1]] + edge[2]
            edges.remove(edge)
        elif dist[edge[1]] == None and dist[edge[0]] != None:
            dist[edge[1]] = dist[edge[0]] + edge[2]
            edges.remove(edge)
    cnt += 1
    if cnt > N: break

for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edges = []
# edges = [[] for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edges.append([u-1,v-1,w])

    # edges[u-1].append([v-1,w])
    # edges[v-1].append([u-1,w])


dist = [None]*N
dist[0] = 0

while len(edges) > 0:
    for edge in edges:
        if dist[edge[0]] == None and dist[edge[1]] != None:
            dist[edge[0]] = dist[edge[1]] + edge[2]
            edges.remove(edge)
        elif dist[edge[1]] == None and dist[edge[0]] != None:
            dist[edge[1]] = dist[edge[0]] + edge[2]
            edges.remove(edge)

for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edge = [[] for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1,w])
    edge[v-1].append([u-1,w])
    sum_w += w

dist = [sum_w]*N
rest = [i for i in range(N)][::-1]

is_finish = False
dist[0] = 0
while len(rest) > 0:
    min_dist = sum_w+1
    min_ptr = -1
    for i in rest:
        if dist[i] < min_dist:
            min_dist = dist[i]
            min_ptr = i
    rest.remove(min_ptr)
    for i in edge[min_ptr]:
        if i[0] in rest:
            if i[0] < min_ptr:
                dist[i[0]] = dist[min_ptr] + i[1]
            elif i[0] > min_ptr:
                dist[i[0]] = dist[min_ptr] + i[1]
for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edge = [[] for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1,w])
    edge[v-1].append([u-1,w])
    sum_w += w

dist = [sum_w]*N
rest = [i for i in range(N)]

is_finish = False
dist[0] = 0
while len(rest) > 0:
    min_dist = sum_w+1
    min_ptr = -1
    for i in rest:
        if dist[i] < min_dist:
            min_dist = dist[i]
            min_ptr = i
    rest.remove(min_ptr)
    for i in edge[min_ptr]:
        if i[0] in rest:
            if i[0] < min_ptr:
                dist[i[0]] = dist[min_ptr] + i[1]
            elif i[0] > min_ptr:
                dist[i[0]] = dist[min_ptr] + i[1]
for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edge = [[] for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1].append([v-1,w])
    edge[v-1].append([u-1,w])
    sum_w += w

dist = [sum_w]*N
comp = [None]*N
# rest = [i for i in range(N)]

is_finish = False
dist[0] = 0
while not is_finish:
    min_dist = sum_w+1
    min_ptr = -1
    for i in range(N):
        if comp[i] == None and dist[i] < min_dist:
            min_dist = dist[i]
            min_ptr = i
    if min_ptr < 0:
        is_finish = True
    else:
        comp[min_ptr] = 1
        for i in edge[min_ptr]:
            if comp[i[0]] == None:
                if i[0] < min_ptr:
                    dist[i[0]] = dist[min_ptr] + i[1]
                elif i[0] > min_ptr:
                    dist[i[0]] = dist[min_ptr] + i[1]

for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N = int(input())
edge = [[None]*N for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1][v-1] = w
    sum_w += w
dist = [sum_w]*N
comp = [None]*N

is_finish = False
dist[0] = 0
while not is_finish:
    min_dist = sum_w+1
    min_ptr = -1
    for i in range(N):
        if comp[i] == None and dist[i] < min_dist:
            min_dist = dist[i]
            min_ptr = i
    if min_ptr < 0:
        is_finish = True
    else:
        comp[min_ptr] = 1
        for i in range(N):
            if comp[i] == None:
                if i < min_ptr and edge[i][min_ptr] != None:
                    dist[i] = dist[min_ptr] + edge[i][min_ptr]
                elif min_ptr < i and edge[min_ptr][i] != None:
                    dist[i] = dist[min_ptr] + edge[min_ptr][i]

for item in dist:
    print(item%2)

Fixed submission:
import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)