import heapq
inf=float("inf")


def prim():
    color=["white" for _ in range(n+1)]
    D=[inf for _ in range(n+1)]
    M=[[] for _ in range(n+1)]

    for u,v,w in UVW:
        M[u].append([w,v])
        M[v].append([w,u])

    queue=[[0,1]]
    heapq.heapify(queue)
    color[1]="gray"
    D[1]=1

    while len(queue)>0:
        num=heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

    return D[1:]


n=int(input())
UVW=[list(map(int,input().split())) for _ in range(n-1)]
for i in prim():
    if i==1:print(i)
    else:print(0) import heapq heapq inf=float("inf") inf float("inf") float "inf" def prim():
    color=["white" for _ in range(n+1)]
    D=[inf for _ in range(n+1)]
    M=[[] for _ in range(n+1)]

    for u,v,w in UVW:
        M[u].append([w,v])
        M[v].append([w,u])

    queue=[[0,1]]
    heapq.heapify(queue)
    color[1]="gray"
    D[1]=1

    while len(queue)>0:
        num=heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

    return D[1:] prim "white" for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) "white" color=["white" for _ in range(n+1)] color ["white" for _ in range(n+1)] inf for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) inf D=[inf for _ in range(n+1)] D [inf for _ in range(n+1)] [] for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [] M=[[] for _ in range(n+1)] M [[] for _ in range(n+1)] for u,v,w in UVW:
        M[u].append([w,v])
        M[v].append([w,u])

     u v w UVW M[u].append([w,v]) [u].append [u] M u append [w,v] w v M[v].append([w,u]) [v].append [v] M v append [w,u] w u queue=[[0,1]] queue [[0,1]] [0,1] 0 1 heapq.heapify(queue) heapq.heapify heapq heapify queue color[1]="gray" color[1] color 1 "gray" D[1]=1 D[1] D 1 1 while len(queue)>0:
        num=heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

     len(queue)>0 len(queue) len queue 0 num=heapq.heappop(queue)[1] num heapq.heappop(queue)[1] heapq.heappop(queue) heapq.heappop heapq heappop queue 1 if color[num]=="black":continue
         color[num]=="black" color[num] color num "black" color[num]="black" color[num] color num "black" for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

     i j M[num] M num if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

     D[j]>i and color[j]!="black" D[j]>i D[j] D j i color[j]!="black" color[j] color j "black" if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                 i%2==0 i%2 i 2 0 color[j]="gray" color[j] color j "gray" heapq.heappush(queue,[i,j]) heapq.heappush heapq heappush queue [i,j] i j return D[1:] D[1:] D 1: 1 n=int(input()) n int(input()) int input() input list(map(int,input().split())) for _ in range(n-1) for _ in range(n-1) _ range(n-1) range n-1 n 1 for _ in range(n-1) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split UVW=[list(map(int,input().split())) for _ in range(n-1)] UVW [list(map(int,input().split())) for _ in range(n-1)] for i in prim():
    if i==1:print(i)
    else:print(0) i prim() prim if i==1:print(i)
    else:print(0) i==1 i 1 inf=float("inf") float("inf") inf n=int(input()) int(input()) n def prim():
    color=["white" for _ in range(n+1)]
    D=[inf for _ in range(n+1)]
    M=[[] for _ in range(n+1)]

    for u,v,w in UVW:
        M[u].append([w,v])
        M[v].append([w,u])

    queue=[[0,1]]
    heapq.heapify(queue)
    color[1]="gray"
    D[1]=1

    while len(queue)>0:
        num=heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

    return D[1:] def prim():
    color=["white" for _ in range(n+1)]
    D=[inf for _ in range(n+1)]
    M=[[] for _ in range(n+1)]

    for u,v,w in UVW:
        M[u].append([w,v])
        M[v].append([w,u])

    queue=[[0,1]]
    heapq.heapify(queue)
    color[1]="gray"
    D[1]=1

    while len(queue)>0:
        num=heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

    return D[1:] prim UVW=[list(map(int,input().split())) for _ in range(n-1)] [list(map(int,input().split())) for _ in range(n-1)] UVW
import heapq
inf=float("inf")


def prim():
    color=["white" for _ in range(n+1)]
    D=[inf for _ in range(n+1)]
    M=[[] for _ in range(n+1)]

    for u,v,w in UVW:
        M[u].append([w,v])
        M[v].append([w,u])

    queue=[[0,1]]
    heapq.heapify(queue)
    color[1]="gray"
    D[1]=1

    while len(queue)>0:
        num=heapq.heappop(queue)[1]
        if color[num]=="black":continue
        color[num]="black"

        for i,j in M[num]:
            if D[j]>i and color[j]!="black":
                if i%2==0:D[j]=D[num]
                else:D[j]=-D[num]
                color[j]="gray"
                heapq.heappush(queue,[i,j])

    return D[1:]


n=int(input())
UVW=[list(map(int,input().split())) for _ in range(n-1)]
for i in prim():
    if i==1:print(i)
    else:print(0)