Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
def dfs(num,hiyo):
    ans[num]=hiyo
    for to,cos in way[num]:
        if ans[to]==-1:
            dfs(to,hiyo+cos)
    
    return 

N=int(input())

way=[[] for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append([v,w])
    way[v].append([u,w])

#lis.sort(key=lambda x:(x[0],x[1]))

dfs(0,0)
#print(ans)
for item in ans:
    print(item%2)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
 
sys.setrecursionlimit(10**7)

def dfs(num,hiyo):
    ans[num]=hiyo
    for to,cos in way[num]:
        if ans[to]==-1:
            dfs(to,hiyo+cos)
    
    return 

N=int(input())

way=[[] for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append([v,w])
    way[v].append([u,w])

#lis.sort(key=lambda x:(x[0],x[1]))

dfs(0,0)
#print(ans)
for item in ans:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def dfs(num,hiyo):
    ans[num]=hiyo
    for item in way[num]:
        if ans[item]==-1:
            dfs(item,hiyo+cost[num][item])
    
    return 

N=int(input())

way=[[] for i in range(N)]
cost=[[0]*N for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append(v)
    way[v].append(u)
    cost[u][v]=w
    cost[v][u]=w

dfs(0,0)

for item in ans:
    print(item%2)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
 
sys.setrecursionlimit(10**7)

def dfs(num,hiyo):
    ans[num]=hiyo
    for to,cos in way[num]:
        if ans[to]==-1:
            dfs(to,hiyo+cos)
    
    return 

N=int(input())

way=[[] for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append([v,w])
    way[v].append([u,w])

#lis.sort(key=lambda x:(x[0],x[1]))

dfs(0,0)
#print(ans)
for item in ans:
    print(item%2)

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def dfs(num,hiyo):
    ans[num]=hiyo
    for item in way[num]:
        if ans[item]==-1:
            dfs(item,hiyo+cost[num][item])
    
    return 

N=int(input())

way=[[] for i in range(N)]
cost=[[0]*N for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append(v)
    way[v].append(u)
    cost[u][v]=w
    cost[v][u]=w

#lis.sort(key=lambda x:(x[0],x[1]))

dfs(0,0)

for item in ans:
    print(item%2)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
 
sys.setrecursionlimit(10**7)

def dfs(num,hiyo):
    ans[num]=hiyo
    for to,cos in way[num]:
        if ans[to]==-1:
            dfs(to,hiyo+cos)
    
    return 

N=int(input())

way=[[] for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append([v,w])
    way[v].append([u,w])

#lis.sort(key=lambda x:(x[0],x[1]))

dfs(0,0)
#print(ans)
for item in ans:
    print(item%2)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**9)

def dfs(loc,num):
    root[loc]=num
    for item in plan[loc]:
        if root[item]==-1:
            dfs(item,num)
    return 0

N,M=map(int,input().split())

P=list(map(int,input().split()))

plan=[[]for i in range(N)]
root=[-1]*N

for _ in range(M):
    a,b=map(int,input().split())
    plan[a-1].append(b-1)
    plan[b-1].append(a-1)

for i in range(N):
    if root[i]==-1:
        dfs(i,i)

ans=0
for i in range(N):
    if root[i]==root[P[i]-1]:
        ans+=1
#print(root)
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
import sys
 
sys.setrecursionlimit(10**7)

def dfs(num,hiyo):
    ans[num]=hiyo
    for to,cos in way[num]:
        if ans[to]==-1:
            dfs(to,hiyo+cos)
    
    return 

N=int(input())

way=[[] for i in range(N)]
ans=[-1]*N

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    way[u].append([v,w])
    way[v].append([u,w])

#lis.sort(key=lambda x:(x[0],x[1]))

dfs(0,0)
#print(ans)
for item in ans:
    print(item%2)