Buggy python submission (verdict: Runtime Error):
# 辺と長さが与えられる
# 頂点1からの各点の距離を計算する
sys.setrecursionlimit(100000)
N = int(input())
path = [[] for _ in range(N + 1)]
for _ in range(N - 1):
  u, v, w = map(int, input().split())
  # 無向グラフ
  path[u].append((v, w))
  path[v].append((u, w))
  # d[0]は使わない
  d = [-1] * (N + 1)

  def walk(i, c):
    if d[i] == -1:
      d[i] = c
      for x, w in path[i]:
        walk(x, c + w)

        walk(1, 0)
        for c in d[1:]:
          print(c)


Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()

Buggy python submission (verdict: Runtime Error):
    sys.setrecursionlimit(100000)
    N = int(input())
    path = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (N + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for c in d[1:]:
        print(c)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

Li = [0] * 2 + [2] * (n -1)

uvws = [list(map(int, input().split())) for _ in range(n - 1)]

while 2 in Li:
    for u, v, w in uvws:
        if w % 2:
            if Li[u] != 2 and Li[v] == 2:
                Li[v] = 1 - Li[u]
            elif Li[u] == 2 and Li[v] != 2:
                Li[u] = 1 - Li[v]
        else:
            if Li[u] != 2 and Li[v] == 2:
                Li[v] = Li[u]
            elif Li[u] == 2 and Li[v] != 2:
                Li[u] = Li[v]

for item in Li[1:]:
    print(item)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

Li = [0] * 2 + [2] * (n -1)

uvws = [list(map(int, input().split())) for _ in range(n - 1)]

while 2 in Li:
    for u, v, w in uvws:
        if w % 2:
            if Li[u] != 2 and Li[v] == 2:
                Li[v] = 1 - Li[u]
            elif Li[u] == 2 and Li[v] != 2:
                Li[u] = 1 - Li[v]
        else:
            if Li[u] != 2 and Li[v] == 2:
                Li[v] = Li[u]
            elif Li[u] == 2 and Li[v] != 2:
                Li[u] = Li[v]

for item in Li[1:]:
    print(item)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

uvws = [list(map(int, input().split())) for _ in range(n-1)]
uvws.sort(key=lambda x: x[0])

zeros = {1}
ones = set()

while len(zeros) + len(ones) < n:
    for uvw in uvws:
        u, v, w = uvw
        if u not in zeros and u not in ones and v in zeros:
            if w % 2:
                ones.add(u)
            else:
                zeros.add(u)
        if u not in zeros and u not in ones and v in ones:
            if w % 2:
                zeros.add(u)
            else:
                ones.add(u)

        if v not in zeros and v not in ones and u in zeros:
            if w % 2:
                ones.add(v)
            else:
                zeros.add(v)
        if v not in zeros and v not in ones and u in ones:
            if w % 2:
                zeros.add(v)
            else:
                ones.add(v)

for i in range(1, n+1):
    print(1 if i in ones else 0)


Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

uvws = [list(map(int, input().split())) for _ in range(n - 1)]

Li = [0] * 2 + [2] * (n-1)

while 2 in Li:
    for uvw in uvws:
        u, v, w = uvw
        if Li[u] != 2 and Li[v] == 2:
            if w % 2 == 0:
                Li[v] = Li[u]
            else:
                Li[v] = 1 - Li[u]
        elif Li[v] != 2 and Li[u] == 2:
            if w % 2 == 0:
                Li[u] = Li[v]
            else:
                Li[u] = 1 - Li[v]

for i in range(n):
    print(Li[i+1])


Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

uvws = [list(map(int, input().split())) for _ in range(n - 1)]

Li = [0] * 2 + [2] * (n-1)

while 2 in Li:
    for uvw in uvws:
        u, v, w = uvw
        if Li[u] != 2:
            if w % 2 == 0:
                Li[v] = Li[u]
            else:
                Li[v] = 1 - Li[u]
        elif Li[v] != 2:
            if w % 2 == 0:
                Li[u] = Li[v]
            else:
                Li[u] = 1 - Li[v]

for i in range(n):
    print(Li[i+1])


Fixed submission:
import sys
sys.setrecursionlimit(100000)

def tree_path():
    # 辺と長さが与えられる
    # 頂点1からの各点の距離を計算する
    # 距離が偶数か奇数かで色分け
    sys.setrecursionlimit(100000)
    n = int(input())
    path = [[] for _ in range(n + 1)]
    for _ in range(n - 1):
        u, v, w = map(int, input().split())
        # 無向グラフ
        path[u].append((v, w))
        path[v].append((u, w))
    # d[0]は使わない
    d = [-1] * (n + 1)

    def walk(i, c):
        if d[i] == -1:
            d[i] = c
            for x, w in path[i]:
                walk(x, c + w)

    walk(1, 0)
    for i in d[1:]:
        print(i % 2)

        
tree_path()