Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2 and a[a[x[n][i][0]]] == -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,y,c = m();
	b[z-1].append([y-1,c])
	b[y-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,y,c = m();
	b[z-1].append([y-1,c])
	b[y-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,y,c = m();
	b[z-1].append([y-1,c])
	b[y-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)
		else:
			continue



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
				oon(x,x[n][i][0],n,p)
			else:
				a[x[n][i][0]] = 1
				oon(x,x[n][i][0],n,p)
		else:
			continue



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
				oon(x,x[n][i][0],n,p)
			else:
				oon(x,x[n][i][0],n,p)
		else:
			continue


nnn = int(input())

a = [1 for i in range(nnn)]
a[0] = 0
b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
import sys,collections as cl,bisect as bs
Max = sys.maxsize

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if  x[n][i][0] != nn:
			if (k + x[n][i][1]) % 2 == 0:
				a[x[n][i][0]] = 0
				oon(x,x[n][i][0],n,(k + x[n][i][1]) % 2)
			else:
				oon(x,x[n][i][0],n,(k + x[n][i][1]) % 2)


nnn = int(input())

a = [1 for i in range(nnn)]
a[0] = 0
b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])

Buggy submission (verdict: Runtime Error):
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

def on(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if not x[n][i][0] == nn:
			if (k + x[n][i][1]) % 2 == 0:
				a[x[n][i][0]] = 0
				on(x,x[n][i][0],n,(k + x[n][i][1]) % 2)
			else:
				on(x,x[n][i][0],n,(k + x[n][i][1]) % 2)


n = int(input())

a = [1 for i in range(n)]
a[0] = 0
b = [[] for i in range(n)]

for i in range(n-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

on(b,0,0,0)

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

Buggy submission (verdict: Runtime Error):
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

def on(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if not x[n][i][0] == nn:
			if (k + x[n][i][1]) % 2 == 0:
				a[x[n][i][0]] = 0
				on(x,x[n][i][0],n,k + x[n][i][1] % 2)
			else:
				on(x,x[n][i][0],n,k + x[n][i][1] % 2)


n = int(input())

a = [1 for i in range(n)]
a[0] = 0
b = [[] for i in range(n)]

for i in range(n-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

on(b,0,0,0)

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