Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [0 for i in range(n)]
stack = deque([0])
used = [0]
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if neibor_n not in used:
            used.append( neibor_n )
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)

Fixed submission:
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [-1 for i in range(n)]
stack = deque([0])
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if dist[neibor_n] == -1:
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


class dfs():
    
    def __init__(self, n, el):
        self.n = n
        self.el = el

        self.evenl = [0 for i in range(n)]
        #self.neibors = dict([(i,[]) for i in range(n)])
        self.neibors = [[] for i in range(n)]


    def calc(self, nf):
        used = []
        used.append( nf )
        stack = deque([ nf ])
        while( len(stack) != 0 ):
            current = stack.popleft()
            current_dist = self.evenl[current]

            for neibor in self.neibors[current]:
                neibor_n, neibor_w = neibor
                if neibor_n not in used:
                    used.append( neibor_n )
                    stack.append( neibor_n )
                    self.evenl[neibor_n] = self.xor( neibor_w, current_dist )                        

    def xor(self, x1,x2):
        return (x1 + x2) % 2

    def set_neibors(self):
        for e in self.el:
            u,v,w = e
            self.neibors[u-1].append( (v-1,w%2) )
            self.neibors[v-1].append( (u-1,w%2) )


n = int(input())
el = []
for i in range(n-1):
    u,v,w = map( int, input().split() )
    el.append( (u,v,w) )    

m = dfs(n,el)
m.set_neibors()
m.calc(0)

for item in m.evenl:
    print(item)

Fixed submission:
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [-1 for i in range(n)]
stack = deque([0])
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if dist[neibor_n] == -1:
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


class dfs():
    
    def __init__(self, n, el):
        self.n = n
        self.el = el

        self.evenl = [0 for i in range(n)]
        self.neibors = dict([(i,[]) for i in range(n)])


    def calc(self, nf):
        used = []
        used.append( nf )
        stack = deque([ nf ])
        while( len(stack) != 0 ):
            current = stack.popleft()
            current_dist = self.evenl[current]
            for neibor in self.neibors[current]:
                neibor_n, neibor_w = neibor
                if neibor_n not in used:
                    used.append( neibor_n )
                    stack.append( neibor_n )
                    self.evenl[neibor_n] = self.xor( neibor_w, current_dist )                        

    def xor(self, x1,x2):
        return (x1 + x2) % 2

    def set_neibors(self):
        for e in self.el:
            u,v,w = e
            self.neibors[u-1].append( (v-1,w%2) )
            self.neibors[v-1].append( (u-1,w%2) )


n = int(input())
el = []
for i in range(n-1):
    u,v,w = map( int, input().split() )
    el.append( (u,v,w) )    

m = dfs(n,el)
m.set_neibors()
m.calc(0)

for item in m.evenl:
    print(item)

Fixed submission:
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [-1 for i in range(n)]
stack = deque([0])
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if dist[neibor_n] == -1:
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)

Buggy python submission (verdict: Runtime Error):
class dfs():
    
    def __init__(self, n, el):
        self.n = n
        self.el = el

        self.evenl = [1 for i in range(n)]
        self.neibors = dict([(i,[[],[]]) for i in range(n)])


    def calc(self, nf, used):
        used.append( nf )
        for node in set( self.neibors[nf][0] ) - set(used) :
            if self.evenl[nf] == 1:
                self.evenl[node] = 1
            else:
                self.evenl[node] = 0

            self.calc(node, used)

        for node in set( self.neibors[nf][1] ) - set(used) :
            if self.evenl[nf] == 1:
                self.evenl[node] = 0
            else:
                self.evenl[node] = 1

            self.calc(node, used)


    def set_neibors(self):
        for e in self.el:
            u,v,w = e
            if w % 2 == 0:
                self.neibors[u-1][0].append(v-1)
                self.neibors[v-1][0].append(u-1)
            else:
                self.neibors[u-1][1].append(v-1)
                self.neibors[v-1][1].append(u-1)

n = int(input())
el = []
for i in range(n-1):
    u,v,w = map( int, input().split() )
    el.append( (u,v,w) )    

m = dfs(n,el)
m.set_neibors()
m.calc(0, [])

for item in m.evenl:
    print(item)

Fixed submission:
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [-1 for i in range(n)]
stack = deque([0])
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if dist[neibor_n] == -1:
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)

Buggy python submission (verdict: Time Limit Exceeded):

import copy

class dfs():
    
    def __init__(self, n, el):
        self.n = n
        self.el = el

        self.evenl = [1 for i in range(n)]
        self.g = [[0 for j in range(n)] for i in range(n)]
        self.pd = set([i for i in range(n)])

    def calc(self, nf, pd):
        pd.remove(nf)
        for i in pd:
            w = self.g[nf][i]
            if w > 0:
                if self.evenl[nf] == 1:
                    if w % 2 == 0:
                        self.evenl[i] = 1
                    else:
                        self.evenl[i] = 0
                else:
                    if w % 2 == 0:
                        self.evenl[i] = 0
                    else:
                        self.evenl[i] = 1

                self.g[nf][i] = 0
                self.g[i][nf] = 0

                self.calc(i, copy.deepcopy(pd) )

    def set_g(self):
        for e in self.el:
            u,v,w = e
            self.g[u-1][v-1] = w
            self.g[v-1][u-1] = w


n = int(input())
el = []
for i in range(n-1):
    u,v,w = map( int, input().split() )
    el.append( (u,v,w) )    

m = dfs(n,el)
m.set_g()
m.calc( 0, set([i for i in range(n)]) )

for item in m.evenl:
    print(item)

Fixed submission:
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [-1 for i in range(n)]
stack = deque([0])
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if dist[neibor_n] == -1:
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)

Buggy python submission (verdict: Time Limit Exceeded):


class dfs():
    
    def __init__(self, n, el):
        self.n = n
        self.el = el

        self.evenl = [1 for i in range(n)]
        self.g = [[0 for j in range(n)] for i in range(n)]

    def calc(self, nf):
        for i in range( len(self.g) ):
            w = self.g[nf][i]
            if w > 0:
                if self.evenl[nf] == 1:
                    if w % 2 == 0:
                        self.evenl[i] = 1
                    else:
                        self.evenl[i] = 0
                else:
                    if w % 2 == 0:
                        self.evenl[i] = 0
                    else:
                        self.evenl[i] = 1

                self.g[nf][i] = 0
                self.g[i][nf] = 0

                self.calc(i)

    def set_g(self):
        for e in self.el:
            u,v,w = e
            self.g[u-1][v-1] = w
            self.g[v-1][u-1] = w


n = int(input())
el = []
for i in range(n-1):
    u,v,w = map( int, input().split() )
    el.append( (u,v,w) )    

m = dfs(n,el)
m.set_g()
m.calc(0)

for item in m.evenl:
    print(item)

Fixed submission:
from collections import deque

n = int(input())
neibors = [[] for i in range(n)]
for i in range(n-1):
    u,v,w = map( int, input().split() )
    neibors[u-1].append( (v-1,w%2) )
    neibors[v-1].append( (u-1,w%2) )

dist = [-1 for i in range(n)]
stack = deque([0])
while( len(stack) != 0 ):
    current = stack.popleft()
    current_dist = dist[current]

    for neibor_n, neibor_w in neibors[current]:
        if dist[neibor_n] == -1:
            stack.append( neibor_n )
            dist[neibor_n] = (neibor_w + current_dist) % 2  

for item in dist:
    print(item)