// 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.1138105823558828x):
#include <bits/stdc++.h>

#define LL long long

#define PII pair<int,int>

#define PIL pair<int,LL>

#define PLI pair<LL,int>

#define PIII pair<int,PII>

#define PLL pair<LL,LL>

#define PLII pair<LL,PII>

#define VI vector<int>

#define VVI vector<VI>

#define VL vector<LL>

#define VVL vector<VL>

#define VPII vector<PII>

#define FF first

#define SS second

#define MP make_pair

#define PB push_back

#define all(x) x.begin(),x.end()

#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'

#define mset(a,v) memset(a,v,sizeof(a))

#define setp(x) cout<<fixed<<setprecision(x)

#define EPS 0.00000000001

#define PI acos(-1)

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

#define rev_loop(i,b,n) for(int i=b;i>=n;--i)

using namespace std;



const int MOD = 1e9 + 7;

const LL MX = 1e5 + 100;

const LL INF = 1e8;



void print_a(VI v)

{

    if(v.size()) cout<<v[0];

    loop(i,1,v.size()) cout<<' '<<v[i];

    cout<<'\n';

}



VVI init_vvi(int n, int m, int val)

{

    return VVI(n,VI(m,val));

}



VVL init_vvl(int n, int m, LL val)

{

    return VVL(n,VL(m,val));

}



VPII g[MX];

int ans[MX];



void dfs(int u)

{

    for(PII p : g[u])

    {

        if(ans[p.FF] == -1)

        {

            if(p.SS & 1) {ans[p.FF] = ans[u] ^ 1;}

            else ans[p.FF] = ans[u];

            dfs(p.FF);

        }

    }

}



int main()

{

    //ofstream out("output.txt");

    //ifstream in("input.txt");

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



    int n, u, v, w;

    cin>>n;

    loop(i,1,n)

    {

        cin>>u>>v>>w;

        g[u].PB({v,w});

        g[v].PB({u,w});

    }



    mset(ans, -1);

    ans[1] = 0;

    dfs(1);

    loop(i,1,n+1) cout<<ans[i]<<'\n';



    /*

    int t,n;

    cin>>t;

    while(t--)

    {

        cin>>n;

        int a[n];

        loop(i,0,n) cin>>a[i];

    }

    */



    /*

    int n;

    cin>>n;

    int a[n];

    loop(i,0,n) cin>>a[i];

    */



    /*

    cout<<ans<<'\n';



    if(f) cout<<"YES\n";

    else cout<<"NO\n";



    if(f) cout<<"Yes\n";

    else cout<<"No\n";

    */



    return 0;

}