Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)


Fixed submission:
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)


Fixed submission:
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

class graph:
    def __init__(self,n):
        self.n = n
        self.con = []
        self.team = -1

    def connect(self,n,dist):
        self.con.append((n,dist))

    def is_edge(self):
        if(len(self.con)==1):
            return True
        else: return False

    def set_team(self,team):
        self.team = team

N = int(input())
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
li = []
edge = -1
for i in range(1,N+1):
    li.append(graph(i))
for i in uvw:
    li[i[0]-1].connect(i[1],i[2])
    li[i[1]-1].connect(i[0],i[2])
for i in li:
    if(i.is_edge()):
        edge=i.n
        break
before = edge
next = edge
li[edge-1].set_team(0)
for i in range(N):
    print(li[next-1].team)
    if(i==N-1):break
    if(li[next-1].con[0][0]==before):
        before = next
        next = li[next-1].con[1][0]
        li[next-1].set_team((li[before-1].team+li[before-1].con[1][1])%2)
    else:
        before = next
        next = next = li[next-1].con[0][0]
        li[next-1].set_team((li[before-1].team+li[before-1].con[0][1])%2)


Fixed submission:
from operator import itemgetter
import sys
sys.setrecursionlimit(1000000)

def dfs(n,team):
    li[n-1] = team
    for i in grp[n-1]:
        if(li[i[0]-1]==-1):
            dfs(i[0],(team+i[1])%2)



N = int(input())
li = [-1]*N
uvw = [[int(x) for x in input().split()]for _ in range(N-1)]
uvw.sort(key=itemgetter(0))
grp = [[]for _ in range(N)]
for i in uvw:
    grp[i[0]-1].append([i[1],i[2]])
    grp[i[1]-1].append([i[0],i[2]])
dfs(1,0)
for i in li:
    print(i)