Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
vertexes=[[] for i in range(N)]
edges=[[int(s) for s in input().split()] for i in range(N-1)]
#頂点ごとに、頂点から伸びる辺のデータを記録
for e in edges:
  vertexes[e[0]-1].append([e[1]-1,e[2]])
  vertexes[e[1]-1].append([e[0]-1,e[2]])

#幅優先探索の開始（v_possibleに入った順に頂点を訪れる）
answer=[-1 for i in range(N)]  #到達していない頂点は-1
answer[0]=0
v_possible=[] #到達可能な頂点と、辺の情報
v=0 #現在の位置
for i in range(N-1):
  for e in vertexes[v]: #行き先の更新
    if answer[e[0]]==-1: #未到達ならv_possibleに追加
      v_possible.append([e[0],v,e[1]]) #[行き先,つながる頂点,距離] 
  v2=v_possible[0] #v_possibleの最初の頂点に移動
  answer[v2[0]]=(answer[v2[1]]+v2[2])%2
  v=v2[0]
  del v_possible[0]
  
#答を出力
for i in range(N):
  print(answer[i])


Fixed submission:
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1): #辺の情報と距離を記録
  u, v, w = map(int, input().split())
  edge[u-1].add((v-1, w))
  edge[v-1].add((u-1, w))

#幅優先検索
dist = [0] * N #距離
stack = [0]
while stack: #stackが空になるまで
  vrt = stack.pop()
  for to, w in edge[vrt].copy():
    stack.append(to)
    dist[to] = dist[vrt] + w
    edge[vrt].discard((to, w))
    edge[to].discard((vrt, w))
    
for i in range(N):
  print(dist[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
vertexes=[[] for i in range(N)]
edges=[[int(s) for s in input().split()] for i in range(N-1)]
#頂点ごとに、頂点から伸びる辺のデータを記録
for e in edges:
  vertexes[e[0]-1].append([e[1]-1,e[2]])
  vertexes[e[1]-1].append([e[0]-1,e[2]])

#幅優先探索の開始（v_possibleに入った順に頂点を訪れる）
answer=[-1 for i in range(N)]  #到達していない頂点は-1
answer[0]=0
v_possible=[] #到達可能な頂点と、辺の情報
v=0 #現在の位置
for i in range(N-1):
  for e in vertexes[v]: #行き先の更新
    v_possible.append([e[0],v,e[1]]) #[行き先,つながる頂点,距離]
  Len=len(v_possible)
  x=0
  for k in range(Len):
    vx=v_possible[k-x]
    if answer[vx[0]]==-1: #まだ訪れていないなら移動
      answer[vx[0]]=(answer[vx[1]]+vx[2])%2
      v=vx[0]
      break
    else: #すでに訪れたなら、その情報は消す
      del v_possible[k-x]
      x+=1

#答を出力
for i in range(N):
  print(answer[i])


Fixed submission:
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1): #辺の情報と距離を記録
  u, v, w = map(int, input().split())
  edge[u-1].add((v-1, w))
  edge[v-1].add((u-1, w))

#幅優先検索
dist = [0] * N #距離
stack = [0]
while stack: #stackが空になるまで
  vrt = stack.pop()
  for to, w in edge[vrt].copy():
    stack.append(to)
    dist[to] = dist[vrt] + w
    edge[vrt].discard((to, w))
    edge[to].discard((vrt, w))
    
for i in range(N):
  print(dist[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
vertexes=[[] for i in range(N)]
edges=[[int(s) for s in input().split()] for i in range(N-1)]
#頂点ごとに、頂点から伸びる辺のデータを記録
for e in edges:
  vertexes[e[0]-1].append([e[1]-1,e[2]])
  vertexes[e[1]-1].append([e[0]-1,e[2]])

#幅優先探索の開始（v_possibleに入った順に頂点を訪れる）
answer=[-1 for i in range(N)]  #到達していない頂点は-1
answer[0]=0
v_possible=[] #到達可能な頂点と、辺の情報
v=0 #現在の位置
for i in range(N-1):
  for e in vertexes[v]: #行き先の更新
    v_possible.append([e[0],v,e[1]]) #[行き先,つながる頂点,距離]
  for j in v_possible:
    if answer[j[0]]==-1: #まだ訪れていないなら移動
      answer[j[0]]=(answer[j[1]]+j[2])%2
      v=j[0]
      break

#答を出力
for i in range(N):
  print(answer[i])


Fixed submission:
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1): #辺の情報と距離を記録
  u, v, w = map(int, input().split())
  edge[u-1].add((v-1, w))
  edge[v-1].add((u-1, w))

#幅優先検索
dist = [0] * N #距離
stack = [0]
while stack: #stackが空になるまで
  vrt = stack.pop()
  for to, w in edge[vrt].copy():
    stack.append(to)
    dist[to] = dist[vrt] + w
    edge[vrt].discard((to, w))
    edge[to].discard((vrt, w))
    
for i in range(N):
  print(dist[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ls=[[int(s) for s in input().split()] for _ in range(n-1)]
ans=[-1]*(n+1)
ans[1]=0
position=1
e_num=n-1
pan=[0]
while e_num>0:
  for i in range(e_num):
    if ls[i][0]==position:
      next_pos=ls[i][1]
      d=ls[i][2]
      ls.pop(i)
      break
    elif ls[i][1]==position:
      next_pos=ls[i][0]
      d=ls[i][2]
      ls.pop(i)
      break
  if next_pos==0:
    position=pan[-1]
    pan.pop(-1)
  else:
    ans[next_pos]=(ans[position]+d)%2
    pan.append(position)
    position=next_pos
    next_pos=0
    e_num-=1
for i in range(1,n+1):
  print(ans[i])
  
  

Fixed submission:
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1): #辺の情報と距離を記録
  u, v, w = map(int, input().split())
  edge[u-1].add((v-1, w))
  edge[v-1].add((u-1, w))

#幅優先検索
dist = [0] * N #距離
stack = [0]
while stack: #stackが空になるまで
  vrt = stack.pop()
  for to, w in edge[vrt].copy():
    stack.append(to)
    dist[to] = dist[vrt] + w
    edge[vrt].discard((to, w))
    edge[to].discard((vrt, w))
    
for i in range(N):
  print(dist[i]%2)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ls=[[int(s) for s in input().split()] for _ in range(n-1)]
ans=[-1]*(n+1)
ans[1]=0
position=1
e_num=n-1
pan=[0]
while e_num>0:
  for i in range(e_num):
    if ls[i][0]==position:
      next_pos=ls[i][1]
      d=ls[i][2]
      ls.pop(i)
      break
    elif ls[i][1]==position:
      next_pos=ls[i][0]
      d=ls[i][2]
      ls.pop(i)
      break
  if next_pos==0:
    position=pan[-1]
    pan.pop(-1)
  else:
    ans[next_pos]=(ans[position]+d)%2
    pan.append(position)
    position=next_pos
    next_pos=0
    e_num-=1
for i in range(1,n+1):
  print(ans[i])
  
  

Fixed submission:
N = int(input())
edge = [set() for i in range(N)]
for i in range(N-1): #辺の情報と距離を記録
  u, v, w = map(int, input().split())
  edge[u-1].add((v-1, w))
  edge[v-1].add((u-1, w))

#幅優先検索
dist = [0] * N #距離
stack = [0]
while stack: #stackが空になるまで
  vrt = stack.pop()
  for to, w in edge[vrt].copy():
    stack.append(to)
    dist[to] = dist[vrt] + w
    edge[vrt].discard((to, w))
    edge[to].discard((vrt, w))
    
for i in range(N):
  print(dist[i]%2)