N=int(eval(input()));p=[[]for _ in range(N+1)]

for _ in range(N-1):u,v,w=list(map(int,input().split()));p[u].append((v,w));p[v].append((u,w))

s=[(1,0)];l=[-1]*N

while s:

 a,w=s.pop()

 l[a-1]=w%2

 for b,c in p[a]:

  if l[b-1]==-1:s.append((b,w+c))

for i in l:print(i)

def solve(string):

    n, *uvw = list(map(int, string.split()))

    p = [[] for _ in range(n + 1)]

    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):

        p[u].append((v, w))

        p[v].append((u, w))

    s = [(1, 0)]

    l = [-1] * n

    while s:

        a, w = s.pop()

        l[a - 1] = w % 2

        for b, c in p[a]:

            if l[b - 1] == -1:

                s.append((b, w + c))

    return "\n".join(str(c) for c in l)





if __name__ == '__main__':

    n = int(eval(input()))

    print((solve('{}\n'.format(n) + '\n'.join([eval(input()) for _ in range(n - 1)]))))

N = int(eval(input()))
p = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = list(map(int, input().split()))
    p[u].append((v, w))
    p[v].append((u, w))
s = [(1, 0)]
l = [-1] * N
while s:
    a, w = s.pop()
    l[a - 1] = w % 2
    for b, c in p[a]:
        if l[b - 1] == -1:
            s.append((b, w + c))
for i in l:
    print(i)

def solve(string):
    n, *uvw = list(map(int, string.split()))
    p = [[] for _ in range(n + 1)]
    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]):
        p[u].append((v, w))
        p[v].append((u, w))
    s = [(1, 0)]
    l = [-1] * n
    while s:
        a, w = s.pop()
        l[a - 1] = w % 2
        for b, c in p[a]:
            if l[b - 1] == -1:
                s.append((b, w + c))
    return "\n".join(str(c) for c in l)


if __name__ == "__main__":
    n = int(eval(input()))
    print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(n - 1)]))))

-N = int(eval(input())) -p = [[] for _ in range(N + 1)] -for _ in range(N - 1): -    u, v, w = list(map(int, input().split())) -    p[u].append((v, w)) -    p[v].append((u, w)) -s = [(1, 0)] -l = [-1] * N -while s: -    a, w = s.pop() -    l[a - 1] = w % 2 -    for b, c in p[a]: -        if l[b - 1] == -1: -            s.append((b, w + c)) -for i in l: -    print(i) +def solve(string): +    n, *uvw = list(map(int, string.split())) +    p = [[] for _ in range(n + 1)] +    for u, v, w in zip(uvw[::3], uvw[1::3], uvw[2::3]): +        p[u].append((v, w)) +        p[v].append((u, w)) +    s = [(1, 0)] +    l = [-1] * n +    while s: +        a, w = s.pop() +        l[a - 1] = w % 2 +        for b, c in p[a]: +            if l[b - 1] == -1: +                s.append((b, w + c)) +    return "\n".join(str(c) for c in l) + + +if __name__ == "__main__": +    n = int(eval(input())) +    print((solve("{}\n".format(n) + "\n".join([eval(input()) for _ in range(n - 1)]))))