Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ

N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

# 深さ優先探索
def dfs(g,v,c):
    if color[v] == -1:
        color[v] = c
        for nv, w in g[v]:
            if color[nv]!=-1:
                continue
            dfs(g,nv,(w+c)%2)

def main():
    dfs(graph, 0, 1)
    for i in color:
        print(i)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ

N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

# 深さ優先探索
def dfs(g,v,c):
    if color[v] == -1:
        color[v] = c
        for nv, w in g[v]:
            if color[nv]==1:
                continue
            nc = c
            if w != 0:
                nc = 1-c
            dfs(g,nv,nc)

def main():
    dfs(graph, 0, 1)
    for i in color:
        print(i)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ

N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

# 深さ優先探索
def dfs(g,v,c):
    if color[v]==-1:
        color[v] = c
        for nv, w in g[v]:
            if color[nv]==-1:
                nc = c
                if w!=0:
                    nc = 1-c
                dfs(g,nv,nc)

def main():
    dfs(graph, 0, 1)
    for i in color:
        print(i)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ

N = int(input())
M = N-1
graph = [[] for _ in range(N)]
seen = [False]*N
color = [-1]*N

# 隣接リストの作成
for i in range(M):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

# 深さ優先探索
def dfs(g,v,c):
    seen[v] = True
    color[v] = c
    for nv, w in g[v]:
        # すでに隣接の色が確定していて同じ色となっている場合終了
        if seen[nv] == True:
            continue
        # 隣接の色が確定していていない場合、先に進めた結果を返す
        nc = c if w==0 else 1-c
        if not dfs(g,nv,nc):
            return False
    return True

def main():
    ret = dfs(graph, 0, 1)
    for i in color:
        print(i)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ

N = int(input())
M = N-1
graph = [[] for _ in range(N)]
seen = [False]*N
color = [-1]*N

# 隣接リストの作成
for i in range(M):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

# 深さ優先探索
def dfs(g,v,c):
    seen[v] = True
    color[v] = c
    for nv, w in g[v]:
        # すでに隣接の色が確定していて同じ色となっている場合終了
        if seen[nv] == True:
            continue
        # 隣接の色が確定していていない場合、先に進めた結果を返す
        nc = c if w==0 else 1-c
        if not dfs(g,nv,nc):
            return False
    return True

def main():
    ret = dfs(graph, 0, 1)

    print(seen)
    print(color)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 二分グラフ
N = int(input())
graph = [[] for _ in range(N)]
color = [-1]*N

# 隣接リストの作成
for i in range(N-1):
    a, b, w = map(int, input().split())
    a -= 1
    b -= 1
    w %= 2
    graph[a].append((b,w))
    graph[b].append((a,w))

next_q = [(0, 0)]
while len(next_q)>0:
    nw, nc = next_q.pop()
    color[nw] = nc
    for nxt, nl in graph[nw]:
        if color[nxt]==-1:
            next_q.append((nxt,(nl+nc)%2))
for i in color:
    print(i)