Buggy python submission (verdict: Runtime Error):
N = int(input())
color = [-1] * N
G = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  G[u-1].append((v-1, w))
  G[v-1].append((u-1, w))

def dfs(v, cur):
  color[v] = cur
  for next_v, w in G[v]:
    if color[next_v] != -1:
      continue
    if w % 2 == 0:
      dfs(next_v, cur)
    else:
      dfs(next_v, 1 - cur)
      
dfs(0, 0)
for i in range(N):
  print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N = int(input())
color = [-1] * N
G = [[] for _ in range(N)]
W = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  G[u-1].append(v-1)
  G[v-1].append(u-1)
  W[u-1].append(w)
  W[v-1].append(w)

def dfs(v, cur):
  color[v] = cur
  for next_v, w in zip(G[v], W[v]):
    if color[next_v] != -1:
      continue
    if w % 2 == 0:
      dfs(next_v, cur)
    else:
      dfs(next_v, 1 - cur)
      
for i in range(N):
  if color[i] != -1:
    continue
  dfs(i, 0)
for i in range(N):
  print(color[i])

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

N = int(input())
color = [-1] * N
G = [[] for _ in range(N)]
W = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  G[u-1].append(v-1)
  G[v-1].append(u-1)
  W[u-1].append(w)
  W[v-1].append(w)

def dfs(v, cur):
  color[v] = cur
  for next_v, w in zip(G[v], W[v]):
    if color[next_v] != -1:
      continue
    if w % 2 == 0:
      dfs(next_v, cur)
    else:
      dfs(next_v, 1 - cur)
      
for i in range(N):
  if color[i] != -1:
    continue
  dfs(i, 0)
for i in range(N):
  print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N = int(input())
color = [-1] * N
G = [[] for _ in range(N)]
W = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  G[u-1].append(v-1)
  G[v-1].append(u-1)
  W[u-1].append(w)
  W[v-1].append(w)

def dfs(v, cur):
  color[v] = cur
  for next_v, w in zip(G[v], W[v]):
    if color[next_v] != -1:
      continue
    if w % 2 == 0:
      dfs(next_v, cur)
    else:
      dfs(next_v, 1 - cur)
      
for i in range(N):
  if color[i] != -1:
    continue
  dfs(i, 0)
for i in range(N):
  print(color[i])

Buggy python submission (verdict: Runtime Error):
N = int(input())
color = [-1] * N
G = [[] for _ in range(N)]
W = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  G[u-1].append(v-1)
  G[v-1].append(u-1)
  W[u-1].append(w)
  W[v-1].append(w)

def dfs(v, cur):
  color[v] = cur
  for next_v, w in zip(G[v], W[v]):
    if color[next_v] != -1:
      continue
    if w % 2 == 0:
      dfs(next_v, cur)
    else:
      dfs(next_v, 1 - cur)
      
for i in range(N):
  if color[i] != -1:
    continue
  dfs(i, 0)
for i in range(N):
  print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N = int(input())
color = [-1] * N
G = [[] for _ in range(N)]
W = [[] for _ in range(N)]
for i in range(N-1):
  u, v, w = map(int, input().split())
  G[u-1].append(v-1)
  G[v-1].append(u-1)
  W[u-1].append(w)
  W[v-1].append(w)

def dfs(v, cur):
  color[v] = cur
  for next_v, w in zip(G[v], W[v]):
    if color[next_v] != -1:
      continue
    if w % 2 == 0:
      dfs(next_v, cur)
    else:
      dfs(next_v, 1 - cur)
      
for i in range(N):
  if color[i] != -1:
    continue
  dfs(i, 0)
for i in range(N):
  print(color[i])