def abc126d():
    n = int(input())
    e = [list() for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        e[u - 1].append([v - 1, w])
        e[v - 1].append([u - 1, w])
    ans = [-1] * n
    ans[0] = 0
    q = e[0].copy()
    while len(q) > 0:
        v, w = q.pop()
        #print(v, w)
        if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
        for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
    for i in ans:
        print(i)
abc126d() def abc126d():
    n = int(input())
    e = [list() for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        e[u - 1].append([v - 1, w])
        e[v - 1].append([u - 1, w])
    ans = [-1] * n
    ans[0] = 0
    q = e[0].copy()
    while len(q) > 0:
        v, w = q.pop()
        #print(v, w)
        if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
        for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
    for i in ans:
        print(i) abc126d n = int(input()) n int(input()) int input() input list() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) list() list e = [list() for _ in range(n)] e [list() for _ in range(n)] for _ in range(n-1):
        u, v, w = map(int, input().split())
        e[u - 1].append([v - 1, w])
        e[v - 1].append([u - 1, w])
     _ range(n-1) range n-1 n 1 u, v, w = map(int, input().split()) u map(int, input().split()) map int input().split() ().split () input split v w e[u - 1].append([v - 1, w]) [u - 1].append [u - 1] e u - 1 u 1 append [v - 1, w] v - 1 v 1 w e[v - 1].append([u - 1, w]) [v - 1].append [v - 1] e v - 1 v 1 append [u - 1, w] u - 1 u 1 w ans = [-1] * n ans [-1] * n [-1] -1 n ans[0] = 0 ans[0] ans 0 0 q = e[0].copy() q e[0].copy() [0].copy [0] e 0 copy while len(q) > 0:
        v, w = q.pop()
        #print(v, w)
        if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
        for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
     len(q) > 0 len(q) len q 0 v, w = q.pop() v q.pop() q.pop q pop w if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
         ans[v] != -1 ans[v] ans v -1 elif w % 2 == 0: ans[v] = 0
         w % 2 == 0 w % 2 w 2 0 for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
     v1 w1 e[v] e v if ans[v1] != -1: continue
             ans[v1] != -1 ans[v1] ans v1 -1 q.append([v1, w+w1]) q.append q append [v1, w+w1] v1 w+w1 w w1 for i in ans:
        print(i) i ans print(i) print i abc126d() abc126d def abc126d():
    n = int(input())
    e = [list() for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        e[u - 1].append([v - 1, w])
        e[v - 1].append([u - 1, w])
    ans = [-1] * n
    ans[0] = 0
    q = e[0].copy()
    while len(q) > 0:
        v, w = q.pop()
        #print(v, w)
        if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
        for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
    for i in ans:
        print(i) def abc126d():
    n = int(input())
    e = [list() for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        e[u - 1].append([v - 1, w])
        e[v - 1].append([u - 1, w])
    ans = [-1] * n
    ans[0] = 0
    q = e[0].copy()
    while len(q) > 0:
        v, w = q.pop()
        #print(v, w)
        if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
        for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
    for i in ans:
        print(i) abc126d
def abc126d():
    n = int(input())
    e = [list() for _ in range(n)]
    for _ in range(n-1):
        u, v, w = map(int, input().split())
        e[u - 1].append([v - 1, w])
        e[v - 1].append([u - 1, w])
    ans = [-1] * n
    ans[0] = 0
    q = e[0].copy()
    while len(q) > 0:
        v, w = q.pop()
        #print(v, w)
        if ans[v] != -1: continue
        elif w % 2 == 0: ans[v] = 0
        else: ans[v] = 1
        for v1, w1 in e[v]:
            if ans[v1] != -1: continue
            q.append([v1, w+w1])
    for i in ans:
        print(i)
abc126d()