Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import sys
input = sys.stdin.readline

class Unionfind:

    __slots__ = ['nodes','size']

    def __init__(self, n):
        self.nodes = list(range(n))
        self.size = [1]*n

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.size[x] += self.size[y]
        self.nodes[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

N = int(input())
edge = [list(map(int,input().split())) for _ in range(N-1)]

uf = Unionfind(N)

for u,v,w in edge:
    u -= 1; v -= 1
    if w % 2 == 1:
        continue
    uf.unite(u,v)

if len(set(uf.nodes)) == 1:
    for _ in range(N):
        print(0)
    exit()

for i in range(N):
    uf.root(i)

w,b = list(set(uf.nodes))

for i in range(N):
    if uf.nodes[i] == w:
        uf.nodes[i] = 0
    elif uf.nodes[i] == b:
        uf.nodes[i] = 1

for v in uf.nodes:
    print(v)

Fixed submission:
import sys
input = sys.stdin.readline

from heapq import heappush, heappop
inf = float('inf')
# (始点,隣接リスト)
def dijkstra(start,ad):
    dist = [inf]*len(ad)
    dist[start] = 0
    pq = [(start,0)]
    while pq:
        v = heappop(pq)[0]
        for nv,nw in ad[v]:
            if dist[nv] > dist[v] + nw:
                dist[nv] = dist[v] + nw
                heappush(pq,(nv,dist[nv]))
    return dist

N = int(input())

ad = [[] for _ in range(N)]

for _ in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1; v -= 1
    ad[u].append((v,w))
    ad[v].append((u,w))

dist = dijkstra(0,ad)

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

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

import sys
input = sys.stdin.readline

class Unionfind:

    __slots__ = ['nodes','size']

    def __init__(self, n):
        self.nodes = list(range(n))
        self.size = [1]*n

    def root(self, x):
        if self.nodes[x] == x:
            return x
        else:
            root_x = self.root(self.nodes[x])
            self.nodes[x] = root_x
            return root_x

    def unite(self, x, y):
        x = self.root(x); y = self.root(y)
        if x == y:
            return
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.size[x] += self.size[y]
        self.nodes[y] = x

    def same(self, x, y):
        return self.root(x) == self.root(y)

N = int(input())
edge = [list(map(int,input().split())) for _ in range(N-1)]

uf = Unionfind(N)

for u,v,w in edge:
    u -= 1; v -= 1
    if w % 2 == 1:
        continue
    uf.unite(u,v)

if len(set(uf.nodes)) == 1:
    for _ in range(N):
        print(0)
    exit()

w,b = list(set(uf.nodes))

for i in range(N):
    if uf.nodes[i] == w:
        uf.nodes[i] = 0
    elif uf.nodes[i] == b:
        uf.nodes[i] = 1

for v in uf.nodes:
    print(v)

Fixed submission:
import sys
input = sys.stdin.readline

from heapq import heappush, heappop
inf = float('inf')
# (始点,隣接リスト)
def dijkstra(start,ad):
    dist = [inf]*len(ad)
    dist[start] = 0
    pq = [(start,0)]
    while pq:
        v = heappop(pq)[0]
        for nv,nw in ad[v]:
            if dist[nv] > dist[v] + nw:
                dist[nv] = dist[v] + nw
                heappush(pq,(nv,dist[nv]))
    return dist

N = int(input())

ad = [[] for _ in range(N)]

for _ in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1; v -= 1
    ad[u].append((v,w))
    ad[v].append((u,w))

dist = dijkstra(0,ad)

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