Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
w = np.zeros(shape = (N,N))
flag = N-1
while flag:
    l = input().split()
    i = int(l[0])-1
    j = int(l[1])-1
    w[i][j] = int(l[2])
    flag -= 1
color = np.ones(shape = (N,))
for i in range(N-1):
    for j in range(i+1,N):
        weight = w[i][j]
        if weight % 2 == 0:
            color[j] = color[i]       
        else :
            color[j] = -color[i]
for i in color:
    if i == -1:
        print(0)
    else:
        print(1)

Fixed submission:
read = input
n = int(read())
v = [[] for i in range(n+1)] # 邻接
used = [0 for i in range(n+1)] # 节点 1~n
def add(f,t,w):
    v[f].append((t, w))
for i in range(n-1):
    f,t,w = map(int, read().split())
    add(f,t,w)
    add(t,f,w)
# 从1出发，贪心即可，1画1，理论不会有回环，总是能画成二分图
from queue import Queue
q = Queue() # 队列
#def dfs(f, s, fa=-1):
#    if s % 2 == 0: 
#        used[f] = 1
#    for t, w in v[f]:
##         print('%d->%d->%d'%(fa, f, t,), s, w)
#        if t == fa:continue
#        dfs(t, w + s, f)
#
#
#dfs(1,0)
q.put_nowait((1, 0, -1)) #(目标节点号，根节点到目标节点的距离，与目标节点相连的上一个节点号)
while not q.empty():
    f, s, fa = q.get_nowait()
    if s % 2 == 0: 
        used[f] = 1 #used数组从1开始填充颜色
    for t, w in v[f]:
#         print('%d->%d->%d'%(fa, f, t,), s, w)
        if t == fa:continue  #fa为与目标节点相连的上一个节点号，防止成环。2->3则，3->2不能再遍历一遍
        q.put_nowait(
            (t, w + s, f)
        )
    
for i in used[1:]: #球号从1开始，故used[0]无意义
    print(used[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
w = np.zeros(shape = (N,N))
flag = N-1
while flag:
    l = input().split()
    i = int(l[0])-1
    j = int(l[1])-1
    w[i][j] = int(l[2])
    flag -= 1
color = np.ones(shape = (N,))
for i in range(N//2 + 1):
    for j in range(i+1,N):
        weight = w[i][j]
        if weight!=0 and weight % 2 == 0:
            color[j] = color[i]       
        else:
            color[j] = -color[i]
for i in color:
    if i == -1:
        print(0)
    else:
        print(1)

Fixed submission:
read = input
n = int(read())
v = [[] for i in range(n+1)] # 邻接
used = [0 for i in range(n+1)] # 节点 1~n
def add(f,t,w):
    v[f].append((t, w))
for i in range(n-1):
    f,t,w = map(int, read().split())
    add(f,t,w)
    add(t,f,w)
# 从1出发，贪心即可，1画1，理论不会有回环，总是能画成二分图
from queue import Queue
q = Queue() # 队列
#def dfs(f, s, fa=-1):
#    if s % 2 == 0: 
#        used[f] = 1
#    for t, w in v[f]:
##         print('%d->%d->%d'%(fa, f, t,), s, w)
#        if t == fa:continue
#        dfs(t, w + s, f)
#
#
#dfs(1,0)
q.put_nowait((1, 0, -1)) #(目标节点号，根节点到目标节点的距离，与目标节点相连的上一个节点号)
while not q.empty():
    f, s, fa = q.get_nowait()
    if s % 2 == 0: 
        used[f] = 1 #used数组从1开始填充颜色
    for t, w in v[f]:
#         print('%d->%d->%d'%(fa, f, t,), s, w)
        if t == fa:continue  #fa为与目标节点相连的上一个节点号，防止成环。2->3则，3->2不能再遍历一遍
        q.put_nowait(
            (t, w + s, f)
        )
    
for i in used[1:]: #球号从1开始，故used[0]无意义
    print(used[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
w = np.zeros(shape = (N,N))
flag = N-1
while flag:
    l = input().split()
    i = int(l[0])-1
    j = int(l[1])-1
    w[i][j] = int(l[2])
    flag -= 1
color = np.ones(shape = (N,))
for i in range(N//2 + 1):
    for j in range(i+1,N):
        weight = w[i][j]
        if weight!=0 and weight % 2 == 0:
            color[j] = color[i]       
        else:
            color[j] = -color[i]
for i in color:
    if i == -1:
        print(0)
    else:
        print(1)

Fixed submission:
read = input
n = int(read())
v = [[] for i in range(n+1)] # 邻接
used = [0 for i in range(n+1)] # 节点 1~n
def add(f,t,w):
    v[f].append((t, w))
for i in range(n-1):
    f,t,w = map(int, read().split())
    add(f,t,w)
    add(t,f,w)
# 从1出发，贪心即可，1画1，理论不会有回环，总是能画成二分图
from queue import Queue
q = Queue() # 队列
#def dfs(f, s, fa=-1):
#    if s % 2 == 0: 
#        used[f] = 1
#    for t, w in v[f]:
##         print('%d->%d->%d'%(fa, f, t,), s, w)
#        if t == fa:continue
#        dfs(t, w + s, f)
#
#
#dfs(1,0)
q.put_nowait((1, 0, -1)) #(目标节点号，根节点到目标节点的距离，与目标节点相连的上一个节点号)
while not q.empty():
    f, s, fa = q.get_nowait()
    if s % 2 == 0: 
        used[f] = 1 #used数组从1开始填充颜色
    for t, w in v[f]:
#         print('%d->%d->%d'%(fa, f, t,), s, w)
        if t == fa:continue  #fa为与目标节点相连的上一个节点号，防止成环。2->3则，3->2不能再遍历一遍
        q.put_nowait(
            (t, w + s, f)
        )
    
for i in used[1:]: #球号从1开始，故used[0]无意义
    print(used[i])

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
w = np.zeros(shape = (N,N))
flag = N-1
while flag:
    l = input.split()
    i = int(l[0])-1
    j = int(l[1])-1
    w[i][j] = int(l[2])
    flag -= 1
color = np.ones(shape = (N,))
for i in range(N//2 + 1):
    for j in range(i+1,N):
        weight = w[i][j]
        if weight!=0 and weight % 2 == 0:
            color[j] = color[i]       
        else:
            color[j] = 0
for i in color:
    print(int(i)) 

Fixed submission:
read = input
n = int(read())
v = [[] for i in range(n+1)] # 邻接
used = [0 for i in range(n+1)] # 节点 1~n
def add(f,t,w):
    v[f].append((t, w))
for i in range(n-1):
    f,t,w = map(int, read().split())
    add(f,t,w)
    add(t,f,w)
# 从1出发，贪心即可，1画1，理论不会有回环，总是能画成二分图
from queue import Queue
q = Queue() # 队列
#def dfs(f, s, fa=-1):
#    if s % 2 == 0: 
#        used[f] = 1
#    for t, w in v[f]:
##         print('%d->%d->%d'%(fa, f, t,), s, w)
#        if t == fa:continue
#        dfs(t, w + s, f)
#
#
#dfs(1,0)
q.put_nowait((1, 0, -1)) #(目标节点号，根节点到目标节点的距离，与目标节点相连的上一个节点号)
while not q.empty():
    f, s, fa = q.get_nowait()
    if s % 2 == 0: 
        used[f] = 1 #used数组从1开始填充颜色
    for t, w in v[f]:
#         print('%d->%d->%d'%(fa, f, t,), s, w)
        if t == fa:continue  #fa为与目标节点相连的上一个节点号，防止成环。2->3则，3->2不能再遍历一遍
        q.put_nowait(
            (t, w + s, f)
        )
    
for i in used[1:]: #球号从1开始，故used[0]无意义
    print(used[i])