Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
d = {}
graph = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  d[(u-1,v-1)] = w
  graph[u-1].append(v-1)
  graph[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
from itertools import deque
queue =deque([])

while queue:
  p = queue.popleft()
  color_p = color[p]
  for i in range(graph[p]):
    if color[i] != -1:
      continue
    else:
      if d[(min(i,p),max(i,p))] %2:
        color[i] = 1 - color_p
      else:
        color[i] = color_p
      queue.push(i)

for i in range(n):
  print(color[i])



Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
d = {}
graph = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  d[(u-1,v-1)] = w
  graph[u-1].append(v-1)
  graph[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
from collections import deque
queue =deque([0])

while queue:
  p = queue.popleft()
  color_p = color[p]
  for i in graph[p]:
    if color[i] != -1:
      continue
    else:
      if d[(min(i,p),max(i,p))] %2:
        color[i] = 1 - color_p
      else:
        color[i] = color_p
      queue.append(i)

for i in range(n):
  print(color[i])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
graph = [[float('inf') for _ in range(n)] for _ in range(n)]
graph1 = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  graph[u-1][v-1] = w
  graph[v-1][u-1] = w
  graph1[u-1].append(v-1)
  graph1[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
def dfs(i,j):#(child, parent)
  for k in graph1[i]:
    if k ==j:
      continue
    if color[k] != -1:
      continue
    if graph[k][i] %2:
      color[k] = 1 -color[i]
    else:
      color[k] = color[i]
    dfs(k,i)
dfs(0,-1)

for i in range(n):
  print(color[i])



Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
d = {}
graph = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  d[(u-1,v-1)] = w
  graph[u-1].append(v-1)
  graph[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
from collections import deque
queue =deque([0])

while queue:
  p = queue.popleft()
  color_p = color[p]
  for i in graph[p]:
    if color[i] != -1:
      continue
    else:
      if d[(min(i,p),max(i,p))] %2:
        color[i] = 1 - color_p
      else:
        color[i] = color_p
      queue.append(i)

for i in range(n):
  print(color[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
graph = [[float('inf') for _ in range(n)] for _ in range(n)]
graph1 = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  graph[u-1][v-1] = w
  graph[v-1][u-1] = w
  graph1[u-1].append(v-1)
  graph1[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
def dfs(i,j):#(child, parent)
  for k in graph1[i]:
    if k ==j:
      continue
    if color[k] != -1:
      continue
    if graph[k][i] %2:
      color[k] = 1 -color[i]
    else:
      color[k] = color[i]
    dfs(k,i)
dfs(0,-1)

for i in range(n):
  print(color[i])



Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
d = {}
graph = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  d[(u-1,v-1)] = w
  graph[u-1].append(v-1)
  graph[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
from collections import deque
queue =deque([0])

while queue:
  p = queue.popleft()
  color_p = color[p]
  for i in graph[p]:
    if color[i] != -1:
      continue
    else:
      if d[(min(i,p),max(i,p))] %2:
        color[i] = 1 - color_p
      else:
        color[i] = color_p
      queue.append(i)

for i in range(n):
  print(color[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
graph = [[float('inf') for _ in range(n)] for _ in range(n)]
graph1 = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  graph[u-1][v-1] = w
  graph[v-1][u-1] = w
  graph1[u-1].append(v-1)
  graph1[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
def dfs(i,j):#(child, parent)
  for k in graph1[i]:
    if k ==j:
      continue
    if color[k] != -1:
      continue
    if graph[k][i] %2:
      color[k] = 1 -color[i]
    else:
      color[k] = color[i]
    dfs(k,i)
dfs(0,-1)

for i in range(n):
  print(color[i])



Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
d = {}
graph = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  d[(u-1,v-1)] = w
  graph[u-1].append(v-1)
  graph[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
from collections import deque
queue =deque([0])

while queue:
  p = queue.popleft()
  color_p = color[p]
  for i in graph[p]:
    if color[i] != -1:
      continue
    else:
      if d[(min(i,p),max(i,p))] %2:
        color[i] = 1 - color_p
      else:
        color[i] = color_p
      queue.append(i)

for i in range(n):
  print(color[i])

Buggy python submission (verdict: Runtime Error):
n = int(input())
graph = [[float('inf') for _ in range(n)] for _ in range(n)]
graph1 = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().slpit())
  graph[u-1][v-1] = w
  graph[v-1][u-1] = w
  graph1[u].append(v)
  graph1[v].append(u)
  
  
color = [-1 for i in range(n)] 
def dfs(i,j):#(child, parent)
  if color[i] != -1:
    return
  if graph[i][j] %2:
    color[i] = 1 -color[j]
  else:
    color[i] = color[j]
  for k in graph1[i]:
    if k ==j:
      continue
    dfs(k,i)
dsf(0,-1)

for i in range(n):
  print(color[i])

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
d = {}
graph = {i:[] for i in range(n)}
for _ in range(n-1):
  u,v,w = map(int,input().split())
  d[(u-1,v-1)] = w
  graph[u-1].append(v-1)
  graph[v-1].append(u-1)
  
  
color = [-1 for i in range(n)] 
color[0] = 0
from collections import deque
queue =deque([0])

while queue:
  p = queue.popleft()
  color_p = color[p]
  for i in graph[p]:
    if color[i] != -1:
      continue
    else:
      if d[(min(i,p),max(i,p))] %2:
        color[i] = 1 - color_p
      else:
        color[i] = color_p
      queue.append(i)

for i in range(n):
  print(color[i])