Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

Dist = [[0 for i in range(N)] for j in range(N)]
Seen = [-1] * N

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

que = [0]
Seen[0] = 0
flag = True
while -1 in Seen:
    now = que.pop()
    for next in range(N):
        if Dist[now][next] == 0:
            continue
        elif Seen[next] == -1:
            que.insert(0, next)
            if Dist[now][next] % 2 == 0:
                Seen[next] = Seen[now]
            else:
                Seen[next] = 1 - Seen[now]
for i in range(N):
    print(Seen[i])

Fixed submission:
N = int(input())

Dist = [[] for j in range(N)]
Seen = [-1] * N

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

que = [0]
Seen[0] = 0
flag = True
while -1 in Seen:
    now = que.pop()
    for next, distance in Dist[now]:
        if Seen[next] == -1:
            que.insert(0, next)
            if distance % 2 == 0:
                Seen[next] = Seen[now]
            else:
                Seen[next] = 1 - Seen[now]
for i in range(N):
    print(Seen[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

Dist = [[0 for i in range(N)] for j in range(N)]
Seen = [-1] * N

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

que = [0]
Seen[0] = 0
flag = True
while -1 in Seen:
    now = que.pop()
    for next in range(N):
        if Dist[now][next] == 0:
            continue
        elif Seen[next] == -1:
            que.insert(0, next)
            if Dist[now][next] % 2 == 0:
                Seen[next] = Seen[now]
            else:
                Seen[next] = 1 - Seen[now]
for i in range(N):
    print(Seen[i])


Fixed submission:
N = int(input())

Dist = [[] for j in range(N)]
Seen = [-1] * N

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

que = [0]
Seen[0] = 0
flag = True
while -1 in Seen:
    now = que.pop()
    for next, distance in Dist[now]:
        if Seen[next] == -1:
            que.insert(0, next)
            if distance % 2 == 0:
                Seen[next] = Seen[now]
            else:
                Seen[next] = 1 - Seen[now]
for i in range(N):
    print(Seen[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

Dist = [[0 for i in range(N)] for j in range(N)]
Seen = [-1] * N

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

que = [0]
Seen[0] = 0
flag = True
while len(que) != 0:
    if not flag:
        break
    now = que.pop()
    for next in range(N):
        if Dist[now][next] == 0:
            continue
        elif Seen[next] == -1:
            que.insert(0, next)
            if Dist[now][next] % 2 == 0:
                Seen[next] = Seen[now]
            else:
                Seen[next] = 1 - Seen[now]
        elif Seen[next] != -1:
            if Dist[now][next] % 2 == (Seen[now] + Seen[next]) % 2:
                continue
            else:
                flag = False
                break

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


Fixed submission:
N = int(input())

Dist = [[] for j in range(N)]
Seen = [-1] * N

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

que = [0]
Seen[0] = 0
flag = True
while -1 in Seen:
    now = que.pop()
    for next, distance in Dist[now]:
        if Seen[next] == -1:
            que.insert(0, next)
            if distance % 2 == 0:
                Seen[next] = Seen[now]
            else:
                Seen[next] = 1 - Seen[now]
for i in range(N):
    print(Seen[i])