Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [False]*n #訪問済み
check[u] = True
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if not check[v[0]]:
            check[v[0]] = True
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append([ipt[1]-1,ipt[2]])
    ar[ipt[1]-1].append([ipt[0]-1,ipt[2]])

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [False]*n #訪問済み
check[u] = True
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if not check[v[0]]:
            check[v[0]] = True
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append([ipt[1]-1,ipt[2]])
    ar[ipt[1]-1].append([ipt[0]-1,ipt[2]])

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [False]*n #訪問済み
check[u] = True

while True:
    if len(queue) == 0:
        break
    u = queue.pop(0)
    for v in ar[u]:
        if not check[v[0]]:
            check[v[0]] = True
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])

for i in range(n):
    print(ans[i]%2)

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append([ipt[1]-1,ipt[2]])
    ar[ipt[1]-1].append([ipt[0]-1,ipt[2]])

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [False]*n #訪問済み
check[u] = True

while True:
    if len(queue) == 0:
        break
    u = queue.pop(0)
    for v in ar[u]:
        if not check[v[0]]:
            check[v[0]] = True
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])

for i in range(len(ans)):
    print(ans[i]%2)

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append([ipt[1]-1,ipt[2]%2])
    ar[ipt[1]-1].append([ipt[0]-1,ipt[2]%2])

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [u] #訪問済み

while True:
    if len(queue) == 0:
        break
    u = queue[0]
    queue.pop(0)
    for v in ar[u]:
        if not v[0] in check:
            check.append(v[0])
            ans[v[0]] = (ans[u] + v[1])%2
            queue.append(v[0])

for i in range(len(ans)):
    print(ans[i])

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[-1 for i in range(n)] for j in range(n)]
ar2 = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1][ipt[1]-1] = ipt[2]%2
    ar[ipt[1]-1][ipt[0]-1] = ipt[2]%2
    ar2[ipt[0]-1].append(ipt[1]-1)
    ar2[ipt[1]-1].append(ipt[0]-1)

ans = [[] for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
check = [u] #訪問済み

while True:
    if len(queue) == 0:
        break
    u = queue[0]
    queue.pop(0)
    for v in ar2[u]:
        if not v in check:
            check.append(v)
            ans[v] = (ans[u] + ar[u][v])%2
            queue.append(v)

for i in range(len(ans)):
    print(ans[i])

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[-1 for i in range(n)] for j in range(n)]
ar2 = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1][ipt[1]-1] = ipt[2]%2
    ar[ipt[1]-1][ipt[0]-1] = ipt[2]%2
    ar2[ipt[0]-1].append(ipt[1]-1)
    ar2[ipt[1]-1].append(ipt[0]-1)

ans = [[] for i in range(n)]
ans[0] = 0

def draw(u,k):
    for v in ar2[u]:
        if v!=k:
            ans[v] = (ans[u] + ar[u][v])%2
            draw(v,u)

draw(0,0)
for i in range(len(ans)):
    print(ans[i])

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ar = [[-1 for i in range(n)] for j in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1][ipt[1]-1] = ipt[2]%2
    ar[ipt[1]-1][ipt[0]-1] = ipt[2]%2

ans = [[] for i in range(n)]
ans[0] = 0

def draw(u,k):
    for v,d in enumerate(ar[u]):
        if d >= 0 and v!=k:
            ans[v] = (ans[u] + d)%2
            draw(v,u)

draw(0,0)
for i in range(len(ans)):
    print(ans[i])

Fixed submission:
n = int(input())
ar = [[] for i in range(n)]
for i in range(n-1):
    ipt = list(map(int,input().split()))
    ar[ipt[0]-1].append((ipt[1]-1,ipt[2]))
    ar[ipt[1]-1].append((ipt[0]-1,ipt[2]))

ans = [-1 for i in range(n)]
u = 0
ans[u] = 0
queue = [u] #キュー
l = 1
while True:
    if l == 0:
        break
    u = queue.pop(0)
    l -= 1
    for v in ar[u]:
        if ans[v[0]] < 0:
            ans[v[0]] = ans[u] + v[1]
            queue.append(v[0])
            l+=1

for i in range(n):
    print(ans[i]%2)