Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + tree[position][i]
            q.append(i)

for i in visit[1:]:
    print(i%2)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
result = [0]*(n+1)
result[uvw[0][1]] = uvw[0][2]
s = uvw[0][0]
del uvw[0]
n_visit = []
horyuu = []
count = n-2
while count > 0:
    for i in range(len(uvw)):
        if uvw[i][1] != s and uvw[i][0] != s:
            if result[uvw[i][0]] == 0 and result[uvw[i][1]] != 0:
                result[uvw[i][0]] =  result[uvw[i][1]] + uvw[i][2]
                count -= 1
            elif result[uvw[i][0]] != 0 and result[uvw[i][1]] == 0:
                result[uvw[i][1]] =  result[uvw[i][0]] + uvw[i][2]
                count -= 1
        else:
            if uvw[i][1] != s and uvw[i][0] == s:
                result[uvw[i][1]] = uvw[i][2]
                count -= 1
            elif uvw[i][0] != s and uvw[i][1] == s:
                result[uvw[i][0]] = uvw[i][2]
                count -= 1
            else:
                horyuu.append(uvw[i])
    uvw = horyuu
    horyuu = []

for i in range(1,n+1):
    if result[i]%2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
uvw.sort()
result = [0]*(n+1)
result[uvw[0][1]] = uvw[0][2]
s = uvw[0][0]
del uvw[0]
n_visit = []
horyuu = []
count = n-2
while count > 0:
    for i in range(len(uvw)):
        if uvw[i][1] != s and uvw[i][0] != s:
            if result[uvw[i][0]] == 0 and result[uvw[i][1]] != 0:
                result[uvw[i][0]] =  result[uvw[i][1]] + uvw[i][2]
                count -= 1
            elif result[uvw[i][0]] != 0 and result[uvw[i][1]] == 0:
                result[uvw[i][1]] =  result[uvw[i][0]] + uvw[i][2]
                count -= 1
        else:
            if uvw[i][1] != s and uvw[i][0] == s:
                result[uvw[i][1]] = uvw[i][2]
                count -= 1
            elif uvw[i][0] != s and uvw[i][1] == s:
                result[uvw[i][0]] = uvw[i][2]
                count -= 1
            else:
                horyuu.append(uvw[i])
    uvw = horyuu
    horyuu = []

for i in range(1,n+1):
    if result[i]%2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
uvw.sort()
result = [0]*(n+1)
result[uvw[0][1]] = uvw[0][2]
s = uvw[0][0]
del uvw[0]
n_visit = []
horyuu = []
count = n-2
while count > 0:
    for i in range(len(uvw)):
        if result[uvw[i][0]] == 0 and result[uvw[i][1]] != 0 and uvw[i][0] != s:
            result[uvw[i][0]] =  result[uvw[i][1]] + uvw[i][2]
            count -= 1
        elif result[uvw[i][0]] != 0 and result[uvw[i][1]] == 0 and uvw[i][1] != s:
            result[uvw[i][1]] =  result[uvw[i][0]] + uvw[i][2]
            count -= 1
        else:
            if uvw[i][1] != s and uvw[i][0] == s:
                result[uvw[i][1]] = uvw[i][2]
                count -= 1
            elif uvw[i][0] != s and uvw[i][1] == s:
                result[uvw[i][0]] = uvw[i][2]
                count -= 1
            else:
                horyuu.append(uvw[i])
    uvw = horyuu
    horyuu = []

for i in range(1,n+1):
    if result[i]%2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
result = [0]*(n+1)
result[uvw[0][1]] = uvw[0][2]
s = uvw[0][0]
del uvw[0]
n_visit = []
horyuu = []
count = n-2
while count > 0:
    for i in range(len(uvw)):
        if result[uvw[i][0]] == 0 and result[uvw[i][1]] != 0 and uvw[i][0] != s:
            result[uvw[i][0]] =  result[uvw[i][1]] + uvw[i][2]
            count -= 1
        elif result[uvw[i][0]] != 0 and result[uvw[i][1]] == 0 and uvw[i][1] != s:
            result[uvw[i][1]] =  result[uvw[i][0]] + uvw[i][2]
            count -= 1
        else:
            if uvw[i][1] != s and uvw[i][0] == s:
                result[uvw[i][1]] = uvw[i][2]
                count -= 1
            elif uvw[i][0] != s and uvw[i][1] == s:
                result[uvw[i][0]] = uvw[i][2]
                count -= 1
            else:
                horyuu.append(uvw[i])
    uvw = horyuu
    horyuu = []

for i in range(1,n+1):
    if result[i]%2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
result = [0]*n
for i in range(n-1):
    if uvw[i][2]%2 == 0:
        result[uvw[i][0]-1] = 1
        result[uvw[i][1]-1] = 1
if sum(result) == n:
    result[uvw[0][1]-1] = 0
    result[uvw[0][2]-1] = 0
for i in result:
    print(i)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
uvw = []
for i in range(n-1):
    uvw.append(list(map(int, input().split(' '))))
result = [0]*n
for i in range(n-1):
    if uvw[i][2]%2 == 0:
        result[uvw[i][0]] = 1
        result[uvw[i][1]] = 1
for i in result:
    print(i)

Fixed submission:
from collections import deque

n = int(input())
visit = [-1 for _ in range(n+1)]
friends = [[] for _ in range(n+1)]
for i in range(n-1):
    u, v, w = map(int, input().split())
    friends[u].append([v, w])
    friends[v].append([u, w])

q = deque([1])
visit[1] = 0
while q:
    position = q.popleft()
    for i, cost in friends[position]:
        if visit[i] < 0:
            visit[i] = visit[position] + cost
            q.append(i)

for i in visit[1:]:
    print(i%2)