#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> ans(N);
    vector<vector<pair<int,int> > > A(N,vector<pair<int,int> > (0));
    for(int i = 0;i<N-1;i++){
        int u,v,w;
        cin >> u >> v >> w;
        A[u-1].push_back(make_pair(v-1,w));
        A[v-1].push_back(make_pair(u-1,w));
    }
    queue<pair<int,int> > q;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    q.push(make_pair(0,0));
    vector<bool> flag(N,false);
    flag[0]=true;
    while (!q.empty())
    {
        pair<int,int> p = q.front();
        int x = p.first;
        for(pair<int,int> pp : A[x]){
            if(!flag[pp.first]){
                q.push(make_pair(pp.first,pp.second+p.second));
                flag[pp.first] = true;
            }
        }
        if(p.second%2==0){
            ans[p.first]=0;
        }else
        {
            ans[p.first]=1;
        }
        q.pop();
        
    }
    for(int i = 0;i<N;i++){
        cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 6784