Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)


def func(v, color):
    if visited[v] != 2:
        return
    visited[v] = color
    for next_v in range(n):
        if graph[v][next_v]:  # vとnext_vが繋がっている場合
            if graph[v][next_v] & 1:
                func(next_v, 1-color)
            else:
                func(next_v, color)


n = int(input())
side = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n-1)]
graph = [[0] * n for _ in range(n)]
visited = [2] * n  # 2は未訪問 0は白 黒は1

for u, v, w in side:
    graph[u-1][v-1] = graph[v-1][u-1] = w

func(0, 0)

for i in visited:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)


def func(v, c):
    for next_v, w in graph[v]:
        if color[next_v] == -1:
            color[next_v] = (c + w) & 1
            func(next_v, c + w) 

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

for _ in range(n-1):
    u, v, w = map(int, sys.stdin.readline().split())
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))


color[0] = 0
func(0, 0)

for i in color:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
from time import time
import sys
sys.setrecursionlimit(10 ** 9)


def func(v, color):
    if visited[v] != 2:
        return
    visited[v] = color
    for next_v in range(n):
        if graph[v][next_v] != 0:  # vとnext_vが繋がっている場合
            if graph[v][next_v] % 2 == 0:
                func(next_v, color)
            else:
                func(next_v, color ^ 1)


n = int(input())
side = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n-1)]
graph = [[0] * n for _ in range(n)]
visited = [2] * n  # 2は未訪問 0は白 黒は1

for u, v, w in side:
    graph[u-1][v-1] = graph[v-1][u-1] = w

func(0, 0)

for i in visited:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)


def func(v, c):
    for next_v, w in graph[v]:
        if color[next_v] == -1:
            color[next_v] = (c + w) & 1
            func(next_v, c + w) 

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

for _ in range(n-1):
    u, v, w = map(int, sys.stdin.readline().split())
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))


color[0] = 0
func(0, 0)

for i in color:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9)


def func(v, color):
    if visited[v] != 2:
        return
    visited[v] = color
    for next_v in range(n):
        if graph[v][next_v] != 0:  # vとnext_vが繋がっている場合
            if graph[v][next_v] % 2 == 0:
                func(next_v, color)
            else:
                func(next_v, color ^ 1)


n = int(input())
side = [list(map(int, sys.stdin.readline().split())) for _ in range(n-1)]
graph = [[0] * n for _ in range(n)]
visited = [2] * n  # 2は未訪問 0は白 黒は1

for u, v, w in side:
    graph[u-1][v-1] = w
    graph[v-1][u-1] = w

func(0, 0)

for i in visited:
    print(i)


Fixed submission:
import sys
sys.setrecursionlimit(10 ** 9)


def func(v, c):
    for next_v, w in graph[v]:
        if color[next_v] == -1:
            color[next_v] = (c + w) & 1
            func(next_v, c + w) 

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

for _ in range(n-1):
    u, v, w = map(int, sys.stdin.readline().split())
    graph[u-1].append((v-1, w))
    graph[v-1].append((u-1, w))


color[0] = 0
func(0, 0)

for i in color:
    print(i)