Buggy python submission (verdict: Runtime Error):
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

N = int(input())
ps = [list(map(int, input().split())) for _ in range(N-1)]
ps.sort()
tree = WeightedUnionFind(N)
for i, j, d in ps:
    tree.union(i, j, d)
for i in range(1, N+1):
    if diff(1, i) % 2 == 0:
        print(1)
    else:
        print(0)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.dist = [0] * n
 
    def root(self, i, d):
        if self.parent[i] == i:
            return i, d
        else:
            self.parent[i], d2 = self.root(self.parent[i], d + self.dist[i])
            return self.parent[i], d2
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j, d):
        i2, d1 = self.root(i, 0)
        j2, d2 = self.root(j, 0)
        if i2 < j2 :
            self.parent[j2] = i2
            self.dist[j] = d1 + d
        else:
            self.parent[i2] = j2
            self.dist[i] = d2 + d
            
N = int(input())
ps = [list(map(int, input().split())) for _ in range(N-1)]
ps = collections.deque(ps)
tree = UnionFind(N)
prv = set([1])
while ps:
    i, j, d = ps.popleft()
    if i in prv or j in prv:
        tree.union(i-1, j-1, d)
        prv.add(i)
        prv.add(j)
    else:
        ps.append([i, j, d])

for d in tree.dist:
    if d % 2 == 0:
        print(1)
    else:
        print(0)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.dist = [0] * n
 
    def root(self, i, d):
        if self.parent[i] == i:
            return i, d
        else:
            self.parent[i], d2 = self.root(self.parent[i], d + self.dist[i])
            return self.parent[i], d2
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j, d):
        i2, d1 = self.root(i, 0)
        j2, d2 = self.root(j, 0)
        if i2 < j2 :
            self.parent[j2] = i2
            self.dist[j] = d1 + d
        else:
            self.parent[i2] = j2
            self.dist[i] = d2 + d
            
N = int(input())
ps = [list(map(int, input().split())) for _ in range(N-1)]
ps = collections.deque(ps)
tree = UnionFind(N)
prv = set([1])
while ps:
    i, j, d = ps.popleft()
    if i in prv or j in prv:
        tree.union(i-1, j-1, d)
        prv.add(i)
        prv.add(j)
    else:
        ps.append([i, j, d])

for d in tree.dist:
    if d % 2 == 0:
        print(1)
    else:
        print(0)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.dist = [0] * n
 
    def root(self, i, d):
        if self.parent[i] == i:
            return i, d
        else:
            self.parent[i], d2 = self.root(self.parent[i], d + self.dist[i])
            return self.parent[i], d2
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j, d):
        i2, d1 = self.root(i, 0)
        j2, d2 = self.root(j, 0)
        if i2 < j2 :
            self.parent[j2] = i2
            self.dist[j] = d1 + d
        else:
            self.parent[i2] = j2
            self.dist[i] = d2 + d
            
N = int(input())
ps = [list(map(int, input().split())) for _ in range(N-1)]
ps.sort()
ps = collections.deque(ps)
tree = UnionFind(N)
prv = set([1])
while ps:
    i, j, d = ps.popleft()
    if i in prv or j in prv:
        tree.union(i-1, j-1, d)
        prv.add(i)
        prv.add(j)
    else:
        ps.append([i, j, d])

for d in tree.dist:
    if d % 2 == 0:
        print(1)
    else:
        print(0)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.dist = [0] * n
 
    def root(self, i, d):
        if self.parent[i] == i:
            return i, d
        else:
            self.parent[i], d2 = self.root(self.parent[i], d + self.dist[i])
            return self.parent[i], d2
    
    def find(self, x, y):
        return self.root(x) == self.root(y)
 
    def union(self, i, j, d):
        i2, d1 = self.root(i, 0)
        j2, d2 = self.root(j, 0)
        if i2 < j2 :
            self.parent[j2] = i2
            self.dist[j] = d1 + d
        else:
            self.parent[i2] = j2
            self.dist[i] = d2 + d
            
N = int(input())
ps = [list(map(int, input().split())) for _ in range(N-1)]
ps.sort()
ps = collections.deque(ps)
tree = UnionFind(N)
prv = set([1])
while ps:
    i, j, d = ps.popleft()
    if i in prv or j in prv:
        tree.union(i-1, j-1, d)
        prv.add(i)
        prv.add(j)
    else:
        ps.append([i, j, d])

for d in tree.dist:
    if d % 2 == 0:
        print(1)
    else:
        print(0)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
    
d = [0]*(n+1) #1から各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:1からの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(1,0,0)
for i in range(n):
    if d[i+1] % 2 == 0:
        print(1)
    else:
        print(0)