Buggy python submission (verdict: Runtime Error):
n = int(input())
edge = [[] for _ in range(n)]

for i in range(n-1):
    a,b,c=map(int, input().split())
    edge[a-1].append([b-1,c])
    edge[b-1].append([a-1,c])
#任意の点から行ける偶数の距離で行けるところを同じ色で塗る。
col = [-1]*n
visited = [0]*n

def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c)


def main():
    dfs(0,1)
    for i in range(n):
        print(max(col[i],0))



if __name__ == '__main__':
    main()


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int", c:"int"):
    for j in a[i]:
        if not visited[j[0]]:
            visited[j[0]]=1
            if j[1]%2==0:
                col[j[0]]=c
            else:
                col[j[0]]=c*-1
            dfs(j[0], col[j[0]])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1].append([v-1, d])
        a[v-1].append([u-1, d])
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[0]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int",c:"int"):
    for j in range(n):
        if a[i][j] and not visited[j]>0:
            visited[j]=1
            if a[i][j]%2==0:
                col[j]=c
            else:
                col[j]=c*-1
            dfs(j, col[j])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1][v-1]=a[v-1][u-1]=d
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int", c:"int"):
    for j in a[i]:
        if not visited[j[0]]:
            visited[j[0]]=1
            if j[1]%2==0:
                col[j[0]]=c
            else:
                col[j[0]]=c*-1
            dfs(j[0], col[j[0]])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1].append([v-1, d])
        a[v-1].append([u-1, d])
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n=int(input())
a = [[0]*n for _ in range(n)]
visited = [0] * n
col = [1]*n
que = deque()

for i in range(n-1):
    u,v,d = map(int, input().split())
    a[u-1][v-1]=a[v-1][u-1]=d

#方針：貪欲に
for i in range(n):
    if a[0][i]!=0:
        que.append([i, 0])
        visited[i]=1
while que:
    x = que.pop()
    for i in range(n):
        if a[x[0]][i]!=0 and not visited[i]:
            que.append([i, x[0]])
            visited[i]=1
    if a[x[0]][x[1]]%2 == 0:
        col[x[0]]=col[x[1]]
    else:
        col[x[0]]=(col[x[1]])*-1

for i in range(n):
    print(max(col[i], 0))



Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int", c:"int"):
    for j in a[i]:
        if not visited[j[0]]:
            visited[j[0]]=1
            if j[1]%2==0:
                col[j[0]]=c
            else:
                col[j[0]]=c*-1
            dfs(j[0], col[j[0]])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1].append([v-1, d])
        a[v-1].append([u-1, d])
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n=int(input())
a = [[0]*n for _ in range(n)]
visited = [0] * n
col = [1]*n
que = deque()

for i in range(n-1):
    u,v,d = map(int, input().split())
    a[u-1][v-1]=a[v-1][u-1]=d

#方針：貪欲に
for i in range(n):
    if a[0][i]!=0:
        que.append([i, a[0][i], 0])
        visited[i]=1

while que:
    x = que.pop()
    for i in range(n):
        if a[x[0]][i]!=0 and not visited[i]:
            que.append([i, a[x[0]][i], x[0]])
            visited[i]=1
    if x[1]%2 == 0:
        col[x[0]]=col[x[2]]
    else:
        col[x[0]]=(col[x[2]])*-1

for i in range(n):
    print(max(col[i], 0))


Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
a = [[]*n for _ in range(n)]
visited = [0] * n
dist = [0]*n
col = [1]*n

def dfs(i:"int", c:"int"):
    for j in a[i]:
        if not visited[j[0]]:
            visited[j[0]]=1
            if j[1]%2==0:
                col[j[0]]=c
            else:
                col[j[0]]=c*-1
            dfs(j[0], col[j[0]])



if __name__ == '__main__':
    for i in range(n-1):
        u,v,d = map(int, input().split())
        a[u-1].append([v-1, d])
        a[v-1].append([u-1, d])
    visited[0]=1
    dfs(0, 1)
    for i in range(n):
        print(col[i] if col[i]>0 else 0)