// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define loop(i,n) for(int i = 0;i < int(n);i++)

#define rloop(i,n) for(int i = int(n);i >= 0;i--)

#define range(i,a,b) for(int i = int(a);i <= int(b);i++)

#define SZ(c) int(c.size())

#define ALL(c) c.begin(), c.end()

#define RALL(c) c.rbegin(), c.rend()

#define PI acos(-1)

#define pb push_back

#define mp make_pair

#define fr first

#define sc second

#define sfi1(v) scanf("%d",&v)

#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)

#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)

#define sfll1(v) scanf("%I64d",&v);

#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)

#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

#define endl '\n'



typedef vector<int> vi;

typedef vector<pair<int,int> > vii;

typedef long long ll;

typedef pair<int, int> pii;



const int N = 1e5 + 5;

vi adj[N];

int p[N] , w[N];

int n;



int f(int u){

    if(u == p[u])return u;

    return p[u] = f(p[u]);

}



bool is_connected(int a , int b){

    return f(a) == f(b);

}



void connect(int a , int b){

    a = f(a);

    b = f(b);

    if(a == b)return;

    if(w[a] < w[b])swap(a,b);

    w[a] += w[b];

    p[b] = a;

}



void init(){

    for(int i = 0 ; i < N ; i++)

        p[i] = i , w[i] = 1;

}



int main()

{



#ifndef ONLINE_JUDGE

	//freopen("in.in", "r", stdin);

	//freopen("out.in", "w", stdout);

#endif

	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



    init();

    vii edges;

    int n , u , v, c;

    cin >> n;

    vi ans(n , -1);

    loop(i,n-1){

        cin >> u >> v >> c;

        u-- , v--;

        if(c&1)edges.pb({u,v});

        else connect(u,v);

    }



    for(auto edge : edges){

        //cout << f(edge.fr) << " " << f(edge.sc) << endl;

        adj[f(edge.fr)].pb(f(edge.sc));

        adj[f(edge.sc)].pb(f(edge.fr));

    }





    queue<int> q;

    ans[f(0)] = 0;

    q.push(f(0));

    while(!q.empty()){

        int u = q.front();

        q.pop();

        for(int nxt : adj[u]){

            if(ans[nxt] == -1){

                ans[nxt] = 1 - ans[u];

                q.push(nxt);

            }

        }

    }



    loop(i,n)cout << ans[f(i)] << endl;





    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.2537594180858385x):
///Bismillahir Rahmanir Rahim

#include "bits/stdc++.h"



#define                           ll                          long long

#define                           int                         ll

#define                           fi                          first

#define                           si                          second

#define                           mp                          make_pair

#define                           pb                          push_back

#define                           pi                          pair<ll,ll>

#define                           clr(x)                      memset(x,0,sizeof(x));

#define                           f(i,l,r)                    for(int i=l;i<=r;i++)

#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)

#define                           done(i)                     cout<<"done = "<<i<<endl;

#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;

#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);



using namespace std;



const ll inf=1e18;

const int mod=1e9+7;

const int M=100005;

vector<pi>adj[M];

int dis[M];

bool vis[M];

void bfs(int src)

{

    queue<int>q;

    q.push(src);

    dis[src]=0;

    vis[src]=1;

    while(!q.empty())

    {

        int u=q.front();

        q.pop();

        for(auto x:adj[u])

        {

            int v=x.fi;

            int w=x.si;

            if(vis[v]==0)

            {



                dis[v]=dis[u]+w;

                vis[v]=1;

                q.push(v);

            }

        }

    }



}

 main()



{



    int n;

    scanf("%lld",&n);

    f(i,1,n-1)

    {

        int u,v,w;

        scanf("%lld%lld%lld",&u,&v,&w);

        adj[u].pb(mp(v,w));

        adj[v].pb(mp(u,w));

    }

    //done("chk")

    bfs(1);

   // done("chk")

    f(i,1,n)

    {

        //done(dis[i])

        if(dis[i]%2==0)

         {

             printf("0\n");

         }

         else printf("1\n");

    }

    return 0;



}