Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)

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

L1=sorted(L,key=lambda x: (x[0],x[1]))
LIST=[[]for i in range(N+1)]

for i in range(len(L)):
    LIST[L1[i][0]].append([L1[i][1],L1[i][2]])

def calc(k):
    global MAP
    for i in range(len(LIST[k])):
        #print(LIST[k],len(LIST[k]))
        if(MAP[LIST[k][i][0]]==-1):
            MAP[LIST[k][i][0]]=(MAP[k]+LIST[k][i][1])%2
            #print(LIST[k][i][0],MAP[LIST[k][i][0]])
            calc(LIST[k][i][0])

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


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

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

L1=sorted(L,key=lambda x: (x[0],x[1]))
LIST=[[]for i in range(N+1)]

for i in range(len(L)):
    LIST[L1[i][0]].append([L1[i][1],L1[i][2]])

def calc(k):
    global MAP
    for i in range(len(LIST[k])):
        #print(LIST[k],len(LIST[k]))
        if(MAP[LIST[k][i][0]]==-1):
            MAP[LIST[k][i][0]]=(MAP[k]+LIST[k][i][1])%2
            #print(LIST[k][i][0],MAP[LIST[k][i][0]])
            calc(LIST[k][i][0])

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

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

N=int(input())
L=[0]*(N-1) 
MAP=[0]*(N+1)
for i in range(N-1):
    L[i]=list(map(int,input().split()))
L1=sorted(L,key=lambda x: (x[0],x[1]))
L2=sorted(L,key=lambda x: (x[1],x[0]))
LIST=[1]


f=0
c=0
k=0
t=LIST[k]
while(len(LIST)<N):
    while(N-1>c):
        if(L1[c][0]==t):
            f=1
            if(LIST.count(L1[c][1])==0):
                LIST.append(L1[c][1])
                MAP[L1[c][1]]=(MAP[L1[c][0]]+L1[c][2])%2
        elif(f==1):
            break
        c+=1
    f=0
    c=0

    while(N-1>c):
        if(L2[c][1]==t):
            f=1
            if(LIST.count(L2[c][0])==0):
                LIST.append(L2[c][0])
                MAP[L2[c][0]]=(MAP[L2[c][1]]+L2[c][2])%2
        elif(f==1):
            break
        c+=1
    f=0
    c=0

    k+=1
    t=LIST[k]




      

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


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

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

L1=sorted(L,key=lambda x: (x[0],x[1]))
LIST=[[]for i in range(N+1)]

for i in range(len(L)):
    LIST[L1[i][0]].append([L1[i][1],L1[i][2]])

def calc(k):
    global MAP
    for i in range(len(LIST[k])):
        #print(LIST[k],len(LIST[k]))
        if(MAP[LIST[k][i][0]]==-1):
            MAP[LIST[k][i][0]]=(MAP[k]+LIST[k][i][1])%2
            #print(LIST[k][i][0],MAP[LIST[k][i][0]])
            calc(LIST[k][i][0])

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

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

N=int(input())
L=[0]*(N-1) 
MAP=[0]*(N+1)
for i in range(N-1):
    L[i]=list(map(int,input().split()))
L1=sorted(L,key=lambda x: (x[0],x[1]))
L2=sorted(L,key=lambda x: (x[1],x[0]))
LIST=[1]


f=0
c=0
k=0
t=LIST[k]
while(len(LIST)<N):
    while(N-1>c):
        if(L1[c][0]==t):
            f=1
            if(LIST.count(L1[c][1])==0):
                LIST.append(L1[c][1])
                MAP[L1[c][1]]=(MAP[L1[c][0]]+L1[c][2])%2
        elif(f==1):
            break
        c+=1
    f=0
    c=0

    while(N-1>c):
        if(L2[c][1]==t):
            f=1
            if(LIST.count(L2[c][0])==0):
                LIST.append(L2[c][0])
                MAP[L2[c][0]]=(MAP[L2[c][1]]+L2[c][2])%2
        elif(f==1):
            break
        c+=1
    f=0
    c=0

    k+=1
    t=LIST[k]




      

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


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

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

L1=sorted(L,key=lambda x: (x[0],x[1]))
LIST=[[]for i in range(N+1)]

for i in range(len(L)):
    LIST[L1[i][0]].append([L1[i][1],L1[i][2]])

def calc(k):
    global MAP
    for i in range(len(LIST[k])):
        #print(LIST[k],len(LIST[k]))
        if(MAP[LIST[k][i][0]]==-1):
            MAP[LIST[k][i][0]]=(MAP[k]+LIST[k][i][1])%2
            #print(LIST[k][i][0],MAP[LIST[k][i][0]])
            calc(LIST[k][i][0])

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