Buggy python submission (verdict: Runtime Error):
N = int(input())
edges = [[]for _ in range(N+1)]
for _ in range(N-1):
    u,v,w = map(int,input().split())
    edges[u].append((v,w%2))
    edges[v].append((u,w%2))
colors = [0]*(N+1)
def dfs(n,p,c):
    colors[n] = c
    for nx,w in edges[n]:
        if nx != p:
            if w%2 == 0:
                dfs(nx,n,c)
            else:
                dfs(nx,n,(c+1)%2)

dfs(1,0,0)
for i in range(1,N+1):
    print(colors[i])

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    import heapq

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush(que,(nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents = [i for i in range(n+1)]
        self.size = [1]*(n+1)
    def find(self,x):
        if self.parents[x]==x:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        xRoot = self.find(x)
        yRoot = self.find(y)
        if xRoot == yRoot:
            return
        if self.size[xRoot]>self.size[yRoot]:
            self.parents[yRoot] = xRoot
        else:
            self.parents[xRoot] = yRoot
            if self.size[xRoot] == self.size[yRoot]:
                self.size[yRoot]+=1
tree = UnionFind(2*N)
for _ in range(N-1):
    u,v,w = map(int,input().split())
    if w%2==0:
        tree.unite(u,v)
        tree.unite(u+N,v+N)
    else:
        tree.unite(u,N+v)
        tree.unite(v,N+u)
print(0)
for i in range(2,N+1):
    if tree.find(1)==tree.find(i):
        print(0)
    else:
        print(1)

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    import heapq

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush(que,(nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()

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

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush((nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    import heapq

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush(que,(nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()

Buggy python submission (verdict: Time Limit Exceeded):
"""
二部グラフの問題。
同じ色に塗られた任意の2頂点について、その距離が偶数である。
-> this means that neighbor nodes' color must be another color.
"""
import sys
sys.setrecursionlimit(200000)
N = int(input())
edges = [{} for _ in range(N+1)]
for i in range(N-1):
    u,v,w = map(int,input().split())
    edges[u][v]=w%2
    edges[v][u]=w%2

color = [0 for _ in range(N+1)]
path = {}
def f(n,c):
    color[n]=c
    path[n]=""
    for v,d in edges[n].items():
        if v not in path:
            nextC = c
            if d == 1:
                nextC = (nextC+1)%2
            f(v,nextC)
f(1,0)

for i in range(1,N+1):
    print(color[i])

Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    import heapq

    N = int(input())
    edges = [[] for _ in range(N+1)]
    for _ in range(N-1):
        u,v,w = map(int,input().split())
        edges[u].append((v,w))
        edges[v].append((u,w))
    
    colors = [-1]*(N+1)
    que = [(0,1)]
    heapq.heapify(que)
    while que:
        c,n = heapq.heappop(que)
        if colors[n] == -1:
            colors[n] = c
            for nx,w in edges[n]:
                if w%2==0:
                    nxC = c
                else:
                    nxC = (c+1)%2
                heapq.heappush(que,(nxC,nx))

    for i in range(1,N+1):
        print(colors[i])

main()