Buggy python submission (verdict: Runtime Error):
def f(x):
  for tmp in links[x]:
    if c[tmp[0]]<0:
      if tmp[1]%2==0:
        c[tmp[0]]=c[x]+0
      else:
        c[tmp[0]]=1-c[x]
      f(tmp[0])

N=int(input())
links=[[] for _ in range(N+1)]
for _ in range(N-1):
  u, v, w=map(int, input().split())
  links[u].append([v, w])
  links[v].append([u, w])
  
c=[-1]*(N+1)
c[1]=0
f(1)

print(*c[1:], sep='\n')

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)

N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo[0]]<0:
      if (nuruyo[1]%2)==0:
        f(nuruyo[0], iro)
      else:
        f(nuruyo[0], 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])

Buggy python submission (verdict: Runtime Error):
N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo[0]]<0:
      if (nuruyo[1]%2)==0:
        f(nuruyo[0], iro)
      else:
        f(nuruyo[0], 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)

N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo[0]]<0:
      if (nuruyo[1]%2)==0:
        f(nuruyo[0], iro)
      else:
        f(nuruyo[0], 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
mat=[[0]*(N+1) for i in range(N+1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  mat[uvw[i][0]][uvw[i][1]]=uvw[i][2]
  mat[uvw[i][1]][uvw[i][0]]=uvw[i][2]
  nodelink[uvw[i][0]].append(uvw[i][1])
  nodelink[uvw[i][1]].append(uvw[i][0])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo]<0:
      if (mat[nuru][nuruyo]%2)==0:
        f(nuruyo, iro)
      else:
        f(nuruyo, 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)

N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo[0]]<0:
      if (nuruyo[1]%2)==0:
        f(nuruyo[0], iro)
      else:
        f(nuruyo[0], 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
mat=[[0]*(N+1) for i in range(N+1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  mat[uvw[i][0]][uvw[i][1]]=uvw[i][2]
  mat[uvw[i][1]][uvw[i][0]]=uvw[i][2]
  nodelink[uvw[i][0]].append(uvw[i][1])
  nodelink[uvw[i][1]].append(uvw[i][0])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=g(nuru)
  for nuruyo in tonari:
    if color[nuruyo]<0:
      if h(nuru, nuruyo)==0:
        f(nuruyo, iro)
      else:
        f(nuruyo, 1-iro)
      
def g(x):
  return nodelink[x]

def h(a, b):
  return mat[a][b]%2

f(1, 0)

for i in range(1, N+1):
  print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)

N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo[0]]<0:
      if (nuruyo[1]%2)==0:
        f(nuruyo[0], iro)
      else:
        f(nuruyo[0], 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])