Buggy python submission (verdict: Time Limit Exceeded):
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]

# params
link = [[] for _ in range(N)]
w = [[None] * N for _ in range(N)]
for u, v, c in UVW:
    u -= 1
    v -= 1
    link[u].append(v)
    link[v].append(u)
    w[u][v] = w[v][u] = c


def dfs(ans, x):
    for y in link[x]:
        if ans[y] is None:
            if w[x][y] % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 0 if ans[x] else 1
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Fixed submission:
#!python3

import sys
sys.setrecursionlimit(10 ** 6)


def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]


# params
link = [[] for _ in range(N)]
for u, v, w in UVW:
    u -= 1
    v -= 1
    link[u].append((v, w))
    link[v].append((u, w))


def dfs(ans, x):
    for y, w in link[x]:
        if ans[y] is None:
            if w % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 0 if ans[x] else 1
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]

# params
link = [[] for _ in range(N)]
w = [[None] * N for _ in range(N)]
for u, v, c in UVW:
    u -= 1
    v -= 1
    link[u].append(v)
    link[v].append(u)
    w[u][v] = w[v][u] = c


def main():
    ans = [None] * N
    ans[0] = 0
    l = [0]
    while l:
        next_l = []
        for i in l:
            for j in link[i]:
                if ans[j] is None:
                    ans[j] = (ans[i] + w[i][j] % 2) % 2
                    next_l.append(j)
        l = next_l

    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Fixed submission:
#!python3

import sys
sys.setrecursionlimit(10 ** 6)


def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]


# params
link = [[] for _ in range(N)]
for u, v, w in UVW:
    u -= 1
    v -= 1
    link[u].append((v, w))
    link[v].append((u, w))


def dfs(ans, x):
    for y, w in link[x]:
        if ans[y] is None:
            if w % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 0 if ans[x] else 1
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

import sys
sys.setrecursionlimit(10 ** 6)


def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]

# params
link = [[] for _ in range(N)]
w = [[None] * N for _ in range(N)]
for u, v, c in UVW:
    u -= 1
    v -= 1
    link[u].append(v)
    link[v].append(u)
    w[u][v] = w[v][u] = c


def dfs(visit, ans, x):
    visit[x] = True
    for y in link[x]:
        if not visit[y]:
            if w[x][y] % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 1 ^ ans[x]
            dfs(visit, ans, y)


def main():
    ans = [None] * N
    visit = [False] * N
    ans[0] = 0
    dfs(visit, ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Fixed submission:
#!python3

import sys
sys.setrecursionlimit(10 ** 6)


def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]


# params
link = [[] for _ in range(N)]
for u, v, w in UVW:
    u -= 1
    v -= 1
    link[u].append((v, w))
    link[v].append((u, w))


def dfs(ans, x):
    for y, w in link[x]:
        if ans[y] is None:
            if w % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 0 if ans[x] else 1
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!python3

def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]

# params
link = [[] for _ in range(N)]
w = [[None] * N for _ in range(N)]
for u, v, c in UVW:
    u -= 1
    v -= 1
    link[u].append(v)
    link[v].append(u)
    w[u][v] = w[v][u] = c


def dfs(ans, x):
    for y in link[x]:
        if ans[y] is None:
            if w[x][y] % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 1 ^ ans[x]
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()


Fixed submission:
#!python3

import sys
sys.setrecursionlimit(10 ** 6)


def LI():
    return list(map(int, input().split()))

# input
N = int(input())
UVW = [LI() for _ in range(N - 1)]


# params
link = [[] for _ in range(N)]
for u, v, w in UVW:
    u -= 1
    v -= 1
    link[u].append((v, w))
    link[v].append((u, w))


def dfs(ans, x):
    for y, w in link[x]:
        if ans[y] is None:
            if w % 2 == 0:
                ans[y] = ans[x]
            else:
                ans[y] = 0 if ans[x] else 1
            dfs(ans, y)


def main():
    ans = [None] * N
    ans[0] = 0
    dfs(ans, 0)
    for a in ans:
        print(a)


if __name__ == "__main__":
    main()