Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v):
	if v == bef_v :
		seen[v] = 0;
	else :
		#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
		ind = 0;
		for i in range(len(G[bef_v][0])) :
			if G[bef_v][0][i] == v :
				ind = i;
		if G[bef_v][1][ind] % 2 :
			seen[v] = int(not seen[bef_v]);
		else :
			seen[v] = seen[bef_v];
	
	for next_v in G[v][0] :
		if seen[next_v]==-1 :
			dfs(G,next_v,v);


n = int(input());
G = [[0]*2 for i in range(n) ];
for i in range(n) :
	G[i][0] = [];
	G[i][1] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u][0].append(v);
	G[v][0].append(u);
	G[u][1].append(w);
	G[v][1].append(w);


seen = [-1]*n;
dfs(G,0,0);

for i in range(n):
	print(seen[i]);
	


Fixed submission:
import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v,ind_num):
	if v == bef_v :
		seen[v] = 0;
	else :
		#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
		if G[bef_v][1][ind_num] % 2 :
			seen[v] = int(not seen[bef_v]);
		else :
			seen[v] = seen[bef_v];
	
	for i in range(len(G[v][0])) :
		next_v = G[v][0][i];
		if seen[next_v]==-1 :
			dfs(G,next_v,v,i);


n = int(input());
G = [[0]*2 for i in range(n) ];
for i in range(n) :
	G[i][0] = [];
	G[i][1] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u][0].append(v);
	G[v][0].append(u);
	G[u][1].append(w);
	G[v][1].append(w);


seen = [-1]*n;
dfs(G,0,0,0);

for i in range(n):
	print(seen[i]);

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v):
	#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
	if weight[bef_v][v] % 2 :
		seen[v] = int(not seen[bef_v]);
	else :
		seen[v] = seen[bef_v];
	
	for next_v in G[v] :
		if seen[next_v]==-1 :
			dfs(G,next_v,v);


n = int(input());
weight = [[0]*n for i in range(n) ];
G = [0]*n;
for i in range(n) :
	G[i] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u].append(v);
	G[v].append(u);
	weight[u][v] = w;
	weight[v][u] = w;


seen = [-1]*n;
seen[0] = 0;
dfs(G,0,0);

for i in range(n):
	print(seen[i]);
	


Fixed submission:
import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v,ind_num):
	if v == bef_v :
		seen[v] = 0;
	else :
		#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
		if G[bef_v][1][ind_num] % 2 :
			seen[v] = int(not seen[bef_v]);
		else :
			seen[v] = seen[bef_v];
	
	for i in range(len(G[v][0])) :
		next_v = G[v][0][i];
		if seen[next_v]==-1 :
			dfs(G,next_v,v,i);


n = int(input());
G = [[0]*2 for i in range(n) ];
for i in range(n) :
	G[i][0] = [];
	G[i][1] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u][0].append(v);
	G[v][0].append(u);
	G[u][1].append(w);
	G[v][1].append(w);


seen = [-1]*n;
dfs(G,0,0,0);

for i in range(n):
	print(seen[i]);

Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v):
	#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
	if weight[bef_v][v] % 2 :
		seen[v] = int(not seen[bef_v]);
	else :
		seen[v] = seen[bef_v];
	
	for next_v in G[v] :
		if seen[next_v]==-1 :
			dfs(G,next_v,v);


n = int(input());
weight = [[0]*n for i in range(n) ];
G = [0]*n;
for i in range(n) :
	G[i] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u].append(v);
	G[v].append(u);
	weight[u][v] = w;
	weight[v][u] = w;


seen = [-1]*n;
seen[0] = 0;
dfs(G,0,0);

for i in range(n):
	print(seen[i]);
	


Fixed submission:
import sys

sys.setrecursionlimit(500*500);

def dfs(G,v,bef_v,ind_num):
	if v == bef_v :
		seen[v] = 0;
	else :
		#print(bef_v,v,G[v],weight[bef_v][v],seen[bef_v])
		if G[bef_v][1][ind_num] % 2 :
			seen[v] = int(not seen[bef_v]);
		else :
			seen[v] = seen[bef_v];
	
	for i in range(len(G[v][0])) :
		next_v = G[v][0][i];
		if seen[next_v]==-1 :
			dfs(G,next_v,v,i);


n = int(input());
G = [[0]*2 for i in range(n) ];
for i in range(n) :
	G[i][0] = [];
	G[i][1] = [];
for i in range(n-1) :
	s = input().split(' ');
	u = int(s[0])-1;
	v = int(s[1])-1;
	w = int(s[2]);
	G[u][0].append(v);
	G[v][0].append(u);
	G[u][1].append(w);
	G[v][1].append(w);


seen = [-1]*n;
dfs(G,0,0,0);

for i in range(n):
	print(seen[i]);