Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
a=[set() for v in range(N+1)]
d=[[-1 for v in range(N+1)] for u in range(N+1)]
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u].add(v);a[v].add(u)
    d[u][v]=d[v][u]=w

#c=[None for v in range(N+1)] # color
d1=[None for v in range(N+1)] # distance from 1

# print(a)
# print(d)

q=deque()
q.append(1);d1[1]=0
while q:
    u=q.popleft()
    for v in a[u]:
        if d1[v] is None:
            d1[v]=d1[u]+d[u][v]
            q.append(v)

# print(d1)
for d1i in d1[1:]:
    print(d1i%2)

Fixed submission:
from collections import deque

N=int(input())
a=[set() for v in range(N)] # 0-initial
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u-1].add((v-1,w))
    a[v-1].add((u-1,w))

d=[-1 for v in range(N)] # distance from 0

q=deque()
q.append(0);d[0]=0
while q:
    u=q.popleft()
    for v,w in a[u]:
        if d[v]==-1:
            d[v]=d[u]+w
            q.append(v)

for di in d:
    print(di%2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
a=[[] for v in range(N+1)]
d=[[-1 for v in range(N+1)] for u in range(N+1)]
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u].append(v);a[v].append(u)
    d[u][v]=d[v][u]=w

#c=[None for v in range(N+1)] # color
d1=[None for v in range(N+1)] # distance from 1

# print(a)
# print(d)

q=deque()
q.append(1);d1[1]=0
while q:
    u=q.popleft()
    for v in a[u]:
        if d1[v] is None:
            d1[v]=d1[u]+d[u][v]
            q.append(v)

# print(d1)
for d1i in d1[1:]:
    print(d1i%2)

Fixed submission:
from collections import deque

N=int(input())
a=[set() for v in range(N)] # 0-initial
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u-1].add((v-1,w))
    a[v-1].add((u-1,w))

d=[-1 for v in range(N)] # distance from 0

q=deque()
q.append(0);d[0]=0
while q:
    u=q.popleft()
    for v,w in a[u]:
        if d[v]==-1:
            d[v]=d[u]+w
            q.append(v)

for di in d:
    print(di%2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
a=[[] for v in range(N+1)]
d=[[-1 for v in range(N+1)] for u in range(N+1)]
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u].append(v);a[v].append(u)
    d[u][v]=d[v][u]=w

c=[None for v in range(N+1)] # color

# print(a)
# print(d)

q=deque()
q.append(1);c[1]=True #;d1[1]=0 
while q:
    u=q.popleft()
    for v in a[u]:
        if c[v] is None:
            c[v]=c[u] if d[u][v]%2==0 else not c[u]
            q.append(v)

for ci in c[1:]:
    print(1 if ci else 0)

Fixed submission:
from collections import deque

N=int(input())
a=[set() for v in range(N)] # 0-initial
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u-1].add((v-1,w))
    a[v-1].add((u-1,w))

d=[-1 for v in range(N)] # distance from 0

q=deque()
q.append(0);d[0]=0
while q:
    u=q.popleft()
    for v,w in a[u]:
        if d[v]==-1:
            d[v]=d[u]+w
            q.append(v)

for di in d:
    print(di%2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
a=[[] for v in range(N+1)]
d=[[-1 for v in range(N+1)] for u in range(N+1)]
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u].append(v);a[v].append(u)
    d[u][v]=d[v][u]=w

c=[None for v in range(N+1)] # color

# print(a)
# print(d)

q=deque()
q.append(1);c[1]=True #;d1[1]=0 
while q:
    u=q.popleft()
    for v in a[u]:
        if c[v] is None:
            c[v]=c[u] if d[u][v]%2==0 else not c[u]
            q.append(v)

for ci in c[1:]:
    print(1 if ci else 0)

Fixed submission:
from collections import deque

N=int(input())
a=[set() for v in range(N)] # 0-initial
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u-1].add((v-1,w))
    a[v-1].add((u-1,w))

d=[-1 for v in range(N)] # distance from 0

q=deque()
q.append(0);d[0]=0
while q:
    u=q.popleft()
    for v,w in a[u]:
        if d[v]==-1:
            d[v]=d[u]+w
            q.append(v)

for di in d:
    print(di%2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
out=[set() for i in range(N+1)]
reached=[False for i in range(N+1)]
same=[[False for j in range(N+1)] for i in range(N+1)]

for i in range(N-1):
    u,v,w=map(int,input().split())
    out[u].add(v)
    out[v].add(u)
    same[u][v]=same[v][u]=w%2==0

q=deque()
q.append(1)
reached[1]=True
same1=[False for i in range(N+1)];same1[1]=True

while q:
    u=q.popleft()
    for v in [v for v in out[u] if not reached[v]]:
        same1[v]=same1[u]==same[u][v]
        reached[v]=True
        q.append(v)

for i in range(1,N+1):
    print(0 if same1[i] else 1)

Fixed submission:
from collections import deque

N=int(input())
a=[set() for v in range(N)] # 0-initial
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u-1].add((v-1,w))
    a[v-1].add((u-1,w))

d=[-1 for v in range(N)] # distance from 0

q=deque()
q.append(0);d[0]=0
while q:
    u=q.popleft()
    for v,w in a[u]:
        if d[v]==-1:
            d[v]=d[u]+w
            q.append(v)

for di in d:
    print(di%2)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N=int(input())
out=[set() for i in range(N+1)]
reached=[False for i in range(N+1)]
same=[[False for j in range(N+1)] for i in range(N+1)]

for i in range(N-1):
    u,v,w=map(int,input().split())
    out[u].add(v)
    out[v].add(u)
    same[u][v]=same[v][u]=w%2==0

q=deque()
q.append(1)
reached[1]=True
same1=[False for i in range(N+1)]; same1[1]=True

while q:
    u=q.popleft()
    for v in out[u]:
        if not reached[v]:
            same1[v]=same1[u]==same[u][v]
            reached[v]=True
            q.append(v)

for i in range(1,N+1):
    print(0 if same1[i] else 1)

Fixed submission:
from collections import deque

N=int(input())
a=[set() for v in range(N)] # 0-initial
for e in range(1,N):
    u,v,w=map(int,input().split())
    a[u-1].add((v-1,w))
    a[v-1].add((u-1,w))

d=[-1 for v in range(N)] # distance from 0

q=deque()
q.append(0);d[0]=0
while q:
    u=q.popleft()
    for v,w in a[u]:
        if d[v]==-1:
            d[v]=d[u]+w
            q.append(v)

for di in d:
    print(di%2)