from collections import deque


n = int(input())
e = {}
for i in range(n-1):
    u,v,w = map(int,input().split())
    if u not in e:
        e[u] = [[v,w]]
    else:
        e[u].append([v,w])

    if v not in e:
        e[v] = [[u,w]]
    else:
        e[v].append([u,w])


que = deque()
que.append([1,0,0])
ans = [-1 for i in range(n)]
ans[0] = 0
no_one = True
flag = True
while True:
    if len(que) == 0:
        break
    top = que.popleft()
    st = top[0]
    for edge in e[st]:
        ecos = edge[1]
        nex = edge[0]
        if ans[nex-1] == -1:
            cos0 = top[1]+ecos
            cos1 = top[2]+ecos

            if cos0 %2 == 0:
                que.append([nex,0,cos1])
                ans[nex-1] = 0
            elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
            else:
                if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

    if not flag:
        break
    # print(que)

for a in ans:
    print(a)
# print(ans) from collections import deque n = int(input()) n int(input()) int input() input e = {} e {} for i in range(n-1):
    u,v,w = map(int,input().split())
    if u not in e:
        e[u] = [[v,w]]
    else:
        e[u].append([v,w])

    if v not in e:
        e[v] = [[u,w]]
    else:
        e[v].append([u,w]) i 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 if u not in e:
        e[u] = [[v,w]]
    else:
        e[u].append([v,w])

     u not in e u e e[u] = [[v,w]] e[u] e u [[v,w]] [v,w] v w e[u].append([v,w]) [u].append [u] e u append [v,w] v w if v not in e:
        e[v] = [[u,w]]
    else:
        e[v].append([u,w]) v not in e v e e[v] = [[u,w]] e[v] e v [[u,w]] [u,w] u w e[v].append([u,w]) [v].append [v] e v append [u,w] u w que = deque() que deque() deque que.append([1,0,0]) que.append que append [1,0,0] 1 0 0 -1 for i in range(n) for i in range(n) i range(n) range n for i in range(n) -1 ans = [-1 for i in range(n)] ans [-1 for i in range(n)] ans[0] = 0 ans[0] ans 0 0 no_one = True no_one True flag = True flag True while True:
    if len(que) == 0:
        break
    top = que.popleft()
    st = top[0]
    for edge in e[st]:
        ecos = edge[1]
        nex = edge[0]
        if ans[nex-1] == -1:
            cos0 = top[1]+ecos
            cos1 = top[2]+ecos

            if cos0 %2 == 0:
                que.append([nex,0,cos1])
                ans[nex-1] = 0
            elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
            else:
                if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

    if not flag:
        break
    # print(que) True if len(que) == 0:
        break
     len(que) == 0 len(que) len que 0 break top = que.popleft() top que.popleft() que.popleft que popleft st = top[0] st top[0] top 0 for edge in e[st]:
        ecos = edge[1]
        nex = edge[0]
        if ans[nex-1] == -1:
            cos0 = top[1]+ecos
            cos1 = top[2]+ecos

            if cos0 %2 == 0:
                que.append([nex,0,cos1])
                ans[nex-1] = 0
            elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
            else:
                if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

     edge e[st] e st ecos = edge[1] ecos edge[1] edge 1 nex = edge[0] nex edge[0] edge 0 if ans[nex-1] == -1:
            cos0 = top[1]+ecos
            cos1 = top[2]+ecos

            if cos0 %2 == 0:
                que.append([nex,0,cos1])
                ans[nex-1] = 0
            elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
            else:
                if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

     ans[nex-1] == -1 ans[nex-1] ans nex-1 nex 1 -1 cos0 = top[1]+ecos cos0 top[1]+ecos top[1] top 1 ecos cos1 = top[2]+ecos cos1 top[2]+ecos top[2] top 2 ecos if cos0 %2 == 0:
                que.append([nex,0,cos1])
                ans[nex-1] = 0
            elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
            else:
                if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

     cos0 %2 == 0 cos0 %2 cos0 2 0 que.append([nex,0,cos1]) que.append que append [nex,0,cos1] nex 0 cos1 ans[nex-1] = 0 ans[nex-1] ans nex-1 nex 1 0 elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
             cos1 %2 == 0 cos1 %2 cos1 2 0 que.append([nex,cos0,0]) que.append que append [nex,cos0,0] nex cos0 0 ans[nex-1] = 1 ans[nex-1] ans nex-1 nex 1 1 if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

     no_one que.append([nex, cos0, 0]) que.append que append [nex, cos0, 0] nex cos0 0 ans[nex - 1] = 1 ans[nex - 1] ans nex - 1 nex 1 1 flag = False flag False break if not flag:
        break
    # print(que) not flag flag break for a in ans:
    print(a)
# print(ans) a ans print(a) print a top = que.popleft() que.popleft() top cos1 = top[2]+ecos top[2]+ecos cos1 v,w = map(int,input().split()) map(int,input().split()) v que = deque() deque() que nex = edge[0] edge[0] nex w = map(int,input().split()) map(int,input().split()) w flag = False False flag n = int(input()) int(input()) n flag = True True flag e = {} {} e ans = [-1 for i in range(n)] [-1 for i in range(n)] ans st = top[0] top[0] st no_one = True True no_one cos0 = top[1]+ecos top[1]+ecos cos0 ecos = edge[1] edge[1] ecos u,v,w = map(int,input().split()) map(int,input().split()) u
from collections import deque


n = int(input())
e = {}
for i in range(n-1):
    u,v,w = map(int,input().split())
    if u not in e:
        e[u] = [[v,w]]
    else:
        e[u].append([v,w])

    if v not in e:
        e[v] = [[u,w]]
    else:
        e[v].append([u,w])


que = deque()
que.append([1,0,0])
ans = [-1 for i in range(n)]
ans[0] = 0
no_one = True
flag = True
while True:
    if len(que) == 0:
        break
    top = que.popleft()
    st = top[0]
    for edge in e[st]:
        ecos = edge[1]
        nex = edge[0]
        if ans[nex-1] == -1:
            cos0 = top[1]+ecos
            cos1 = top[2]+ecos

            if cos0 %2 == 0:
                que.append([nex,0,cos1])
                ans[nex-1] = 0
            elif cos1 %2 == 0:
                que.append([nex,cos0,0])
                ans[nex-1] = 1
            else:
                if no_one:
                    que.append([nex, cos0, 0])
                    ans[nex - 1] = 1
                else:
                    flag = False
                    break

    if not flag:
        break
    # print(que)

for a in ans:
    print(a)
# print(ans)