Problem:
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied:    * For any two vertices painted in the same color, the distance between them is an even number.  Find a coloring of the vertices that satisfies the condition and print it. It can be proved that at least one such coloring exists under the constraints of this problem.

Incorrect submission (verdict: Wrong Answer):
class POTENTIAL_UNION_FIND(object):
    def __init__(self, n):
        self.parent = [-1 for i in range(n)]
        self.diff_p = [0 for i in range(n)]
 
    def root(self, x): 
        if self.parent[x] < 0:
            return x
        else:
            rx = self.root(self.parent[x]) 
            self.diff_p[x] += self.diff_p[self.parent[x]] 
            self.parent[x] = rx 
            return rx
 
    def size(self,x): 
        return -self.parent[self.root(x)]

    def merge(self, x, y, dxy): 
        rx = self.root(x) 
        ry = self.root(y) 
        dxy += self.diff_p[x] - self.diff_p[y] 
        x,y=rx,ry
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: 
            x,y,dxy=y,x,-dxy
        self.parent[x] += self.parent[y] 
        self.parent[y] = x 
        self.diff_p[y] = dxy 
        return True
 
    def issame(self, x, y): 
        return self.root(x) == self.root(y)
        
    def diff(self,x,y): 
        if self.root(x) == self.root(y): 
            return self.diff_p[y] - self.diff_p[x]
        else:
            return None

n=int(input())
u=POTENTIAL_UNION_FIND(n)
for i in range(n-1):
    a,b,c=map(int,input().split())
    u.merge(a-1,b-1,c)
for i in u.diff_p:
    if i%2==0:
        print(1)
    else:
        print(0)

Fixed, accepted submission:
class POTENTIAL_UNION_FIND(object):
    def __init__(self, n):
        self.parent = [-1 for i in range(n)]
        self.diff_p = [0 for i in range(n)]
 
    def root(self, x): 
        if self.parent[x] < 0:
            return x
        else:
            rx = self.root(self.parent[x]) 
            self.diff_p[x] += self.diff_p[self.parent[x]] 
            self.parent[x] = rx 
            return rx
 
    def size(self,x): 
        return -self.parent[self.root(x)]

    def merge(self, x, y, dxy): 
        rx = self.root(x) 
        ry = self.root(y) 
        dxy += self.diff_p[x] - self.diff_p[y] 
        x,y=rx,ry
        if x == y:
            return False
        if self.parent[x] > self.parent[y]: 
            x,y,dxy=y,x,-dxy
        self.parent[x] += self.parent[y] 
        self.parent[y] = x 
        self.diff_p[y] = dxy 
        return True
 
    def issame(self, x, y): 
        return self.root(x) == self.root(y)
        
    def diff(self,x,y): 
        if self.root(x) == self.root(y): 
            return self.diff_p[y] - self.diff_p[x]
        else:
            return None

n=int(input())
u=POTENTIAL_UNION_FIND(n)
for i in range(n-1):
    a,b,c=map(int,input().split())
    u.merge(a-1,b-1,c)
for i in range(n):
    print(u.diff(0,i)%2)