Buggy python submission (verdict: Runtime Error):
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


def dfs(vertex, colors, visited, cur_dist, connection):
    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    visited.add(vertex)

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            dfs(nextVertex, colors, visited, cur_dist+connection[vertex][nextVertex], connection)
    

if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()
dfs(0, colors, visited, 0, connection)

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")


Fixed submission:
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()

stck = [(0,0)]
visited.add(0)

while len(stck)>0:
    vertex, cur_dist = stck.pop(-1)

    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            visited.add(nextVertex)
            stck.append((nextVertex, cur_dist+connection[vertex][nextVertex]))

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")

Buggy python submission (verdict: Runtime Error):
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


def dfs(vertex, colors, visited, cur_dist, connection):
    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    visited.add(vertex)

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            dfs(nextVertex, colors, visited, cur_dist+connection[vertex][nextVertex], connection)
    

if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()
dfs(0, colors, visited, 0, connection)

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")


Fixed submission:
import collections, math, bisect

local = False
if local:
    file = open("input.txt", "r")
    import time

def inp():
    if local:
        return file.readline().rstrip()
    else:
        return input().rstrip()

def ints():
    return [int(_) for _ in inp().split()]


if local:
    start=time.time()

N = int(inp())

connection = [dict() for i in range(N)]

for i in range(1, N):
    u,v,w = ints()

    connection[u-1][v-1] = w
    connection[v-1][u-1] = w

colors = ["0"]*N
visited = set()

stck = [(0,0)]
visited.add(0)

while len(stck)>0:
    vertex, cur_dist = stck.pop(-1)

    if cur_dist%2==0:
        colors[vertex] = "0"
    else:
        colors[vertex] = "1"

    for nextVertex in connection[vertex]:
        if nextVertex not in visited:
            visited.add(nextVertex)
            stck.append((nextVertex, cur_dist+connection[vertex][nextVertex]))

for c in colors:
    print(c)


if local:
    fin = (time.time()-start)*1000
    print("{:.2f}".format(fin) + "ms")