Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import coo_matrix
from scipy.sparse.csgraph import dijkstra

N=int(input())
R=[]
C=[]
W=[]

for i in range(N-1):
    u, v, w = [int(i) for i in input().split()]
    R.append(u-1)
    C.append(v-1)
    W.append(w)
    R.append(v-1)
    C.append(u-1)
    W.append(w)
g = coo_matrix((W, (R, C)), shape=(N, N)).tocsr()
d = dijkstra(g, indices=0 ,directed=1, unweighted=False)
for i in d:
    print(int(i) % 2)



Fixed submission:
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
N = int(input())
for i in range(N-1):
    u, v, w = [int(i) for i in input().split()]
    g.add_edge(u-1, v-1, w)
    g.add_edge(v-1, u-1, w)

d = Dijkstra(g, 0)

ans = []
for i in range(N):
    if d.dist[i] % 2 == 0 :
        ans.append(0)
    else:
        ans.append(1)

if sum(ans)==0:
    ans[-1] = 1

for i in range(N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import coo_matrix
from scipy.sparse.csgraph import dijkstra

N=int(input())
R=[]
C=[]
W=[]

for i in range(N-1):
    u, v, w = [int(i) for i in input().split()]
    R.append(u-1)
    C.append(v-1)
    W.append(w)
g = coo_matrix((W, (R, C)), shape=(N, N)).tocsr()
d = dijkstra(g, indices=0 ,directed=False, unweighted=False)

for i in d:
    print(int(i) % 2)



Fixed submission:
from collections import defaultdict
from heapq import heappop, heappush


class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
N = int(input())
for i in range(N-1):
    u, v, w = [int(i) for i in input().split()]
    g.add_edge(u-1, v-1, w)
    g.add_edge(v-1, u-1, w)

d = Dijkstra(g, 0)

ans = []
for i in range(N):
    if d.dist[i] % 2 == 0 :
        ans.append(0)
    else:
        ans.append(1)

if sum(ans)==0:
    ans[-1] = 1

for i in range(N):
    print(ans[i])