Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

dic = {}
dic_d = {}
visited = [0]*(N+1)
for i in range(N-1):
    if visited[L[i][0]] == 1:
        dic[L[i][0]].append(L[i][1])
        dic_d[L[i][0]].append(L[i][2])
    else:
        dic[L[i][0]] = [L[i][1]]
        dic_d[L[i][0]] = [L[i][2]]
        visited[L[i][0]] = 1
    if visited[L[i][1]] == 1:
        dic[L[i][1]].append(L[i][0])
        dic_d[L[i][1]].append(L[i][2])
    else:
        dic[L[i][1]] = [L[i][0]]
        dic_d[L[i][1]] = [L[i][2]]
        visited[L[i][1]] = 1

ans_list = ["0"]*(N+1)
q = [1]
D = [0]
while q:
    v = q.pop(0)
    d = D.pop(0)
    for i in range(len(dic[v])):
        if visited[dic[v][i]] == 1:
            q.append(dic[v][i])
            D.append((d+dic_d[v][i])%2)
            visited[dic[v][i]] = 2
            if (d+dic_d[v][i])%2 == 1:
                ans_list[dic[v][i]] = "1"
                
for i in range(1, N+1):
    print(ans_list[i])

Fixed submission:
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ 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])
    
d = [0]*(N)

q = deque()
q.append([0, 0])
visited = [0]*(N)
while q:
    temp = q.pop()
    for L in edge[temp[0]]:
        if visited[L[0]] == 0:
            d[L[0]] = L[1] + temp[1]
            q.append([L[0], d[L[0]]])
            visited[L[0]] = 1
            
for i in range(N):
    print(d[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

dic = {}
dic_d = {}
visited = [0]*(N+1)
for i in range(N-1):
    if visited[L[i][0]] == 1:
        dic[L[i][0]].append(L[i][1])
        dic_d[L[i][0]].append(L[i][2])
    else:
        dic[L[i][0]] = [L[i][1]]
        dic_d[L[i][0]] = [L[i][2]]
        visited[L[i][0]] = 1
    if visited[L[i][1]] == 1:
        dic[L[i][1]].append(L[i][0])
        dic_d[L[i][1]].append(L[i][2])
    else:
        dic[L[i][1]] = [L[i][0]]
        dic_d[L[i][1]] = [L[i][2]]
        visited[L[i][1]] = 1

ans_list = ["0"]*(N+1)
q = [1]
D = [0]
visited = [0]*(N+1)
while len(q) > 0:
    v = q.pop(0)
    d = D.pop(0)
    for i in range(len(dic[v])):
        if visited[dic[v][i]] == 0:
            q.append(dic[v][i])
            D.append(d+dic_d[v][i])
            visited[dic[v][i]] = 1
            if (d+dic_d[v][i])%2 == 1:
                ans_list[dic[v][i]] = "1"
                
for i in range(1, N+1):
    print(ans_list[i])

Fixed submission:
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ 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])
    
d = [0]*(N)

q = deque()
q.append([0, 0])
visited = [0]*(N)
while q:
    temp = q.pop()
    for L in edge[temp[0]]:
        if visited[L[0]] == 0:
            d[L[0]] = L[1] + temp[1]
            q.append([L[0], d[L[0]]])
            visited[L[0]] = 1
            
for i in range(N):
    print(d[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

dic = {}
visited = [0]*(N+1)
for i in range(N-1):
    if visited[L[i][0]] == 1:
        dic[L[i][0]].append([L[i][1], L[i][2]])
    else:
        dic[L[i][0]] = [[L[i][1], L[i][2]]]
        visited[L[i][0]] = 1
    if visited[L[i][1]] == 1:
        dic[L[i][1]].append([L[i][0], L[i][2]])
    else:
        dic[L[i][1]] = [[L[i][0], L[i][2]]]
        visited[L[i][1]] = 1

ans_list = ["0"]*(N+1)
q = [[1, 0]]
visited = [0]*(N+1)
while len(q) > 0:
    t = q.pop(0)
    v = t[0]
    d = t[1]
    for i in range(len(dic[v])):
        if visited[dic[v][i][0]] == 0:
            q.append([dic[v][i][0], d+dic[v][i][1]])
            visited[dic[v][i][0]] = 1
            if (d+dic[v][i][1])%2 == 1:
                ans_list[dic[v][i][0]] = "1"
                
for i in range(1, N+1):
    print(ans_list[i])

Fixed submission:
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ 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])
    
d = [0]*(N)

q = deque()
q.append([0, 0])
visited = [0]*(N)
while q:
    temp = q.pop()
    for L in edge[temp[0]]:
        if visited[L[0]] == 0:
            d[L[0]] = L[1] + temp[1]
            q.append([L[0], d[L[0]]])
            visited[L[0]] = 1
            
for i in range(N):
    print(d[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

dic = {}
for i in range(N-1):
    if L[i][0] in dic:
        dic[L[i][0]].append([L[i][1], L[i][2]])
    else:
        dic[L[i][0]] = [[L[i][1], L[i][2]]]
    if L[i][1] in dic:
        dic[L[i][1]].append([L[i][0], L[i][2]])
    else:
        dic[L[i][1]] = [[L[i][0], L[i][2]]]

ans_list = ["0"]*(N+1)
q = [[1, 0]]
visited = [0]*(N+1)
while len(q) > 0:
    t = q.pop(0)
    v = t[0]
    d = t[1]
    for i in range(len(dic[v])):
        if visited[dic[v][i][0]] == 0:
            q.append([dic[v][i][0], d+dic[v][i][1]])
            visited[dic[v][i][0]] = 1
            if (d+dic[v][i][1])%2 == 1:
                ans_list[dic[v][i][0]] = "1"
                
for i in range(1, N+1):
    print(ans_list[i])

Fixed submission:
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ 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])
    
d = [0]*(N)

q = deque()
q.append([0, 0])
visited = [0]*(N)
while q:
    temp = q.pop()
    for L in edge[temp[0]]:
        if visited[L[0]] == 0:
            d[L[0]] = L[1] + temp[1]
            q.append([L[0], d[L[0]]])
            visited[L[0]] = 1
            
for i in range(N):
    print(d[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

dic = {}
for i in range(N-1):
    if L[i][0] in dic:
        dic[L[i][0]].append([L[i][1], L[i][2]])
    else:
        dic[L[i][0]] = [[L[i][1], L[i][2]]]
    if L[i][1] in dic:
        dic[L[i][1]].append([L[i][0], L[i][2]])
    else:
        dic[L[i][1]] = [[L[i][0], L[i][2]]]

ans_list = ["0"]*(N+1)
q = [[1, 0]]
visited = []
while len(q) > 0:
    t = q.pop(0)
    v = t[0]
    d = t[1]
    for i in range(len(dic[v])):
        if dic[v][i][0] not in visited:
            q.append([dic[v][i][0], d+dic[v][i][1]])
            visited.append(dic[v][i][0])
            if (d+dic[v][i][1])%2 == 1:
                ans_list[dic[v][i][0]] = "1"
                
for i in range(1, N+1):
    print(ans_list[i])

Fixed submission:
from collections import deque

N = int(input())
edge = [[] for _ in range(N)]
for _ 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])
    
d = [0]*(N)

q = deque()
q.append([0, 0])
visited = [0]*(N)
while q:
    temp = q.pop()
    for L in edge[temp[0]]:
        if visited[L[0]] == 0:
            d[L[0]] = L[1] + temp[1]
            q.append([L[0], d[L[0]]])
            visited[L[0]] = 1
            
for i in range(N):
    print(d[i]%2)