stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define lli long long int

#define pii pair<int,int>

#define pll pair<lli,lli>

#define vi  vector<int>

#define vii vector<pair<int,int>>

#define vll vector<lli>

#define pb  push_back

#define mp  make_pair

#define ss  second

#define ff  first

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

#define BLACK 0

#define WHITE 1

#define piii pair<int,pii>

const int maxn = 2e5+9;

vector<pii>adj[maxn];

int vis[maxn];

int color[maxn];

void dfs(int curr,int col)

{

    vis[curr]=1;

    color[curr]=col;

    for(pii child:adj[curr])

    {

        if(vis[child.ff]==0)

        {

            int w=child.ss;

            if(w%2==0)dfs(child.ff,col);

            else dfs(child.ff,col^1);

        }

    }

}

void solve()

{

    int n;cin>>n;

    for(int i=1;i<n;i++)

    {

        int a,b,c;cin>>a>>b>>c;

        adj[a].pb(mp(b,c));

        adj[b].pb(mp(a,c));

    }

    dfs(1,BLACK);

    for(int i=1;i<=n;i++)

    {

        cout<<color[i]<<endl;

    }



}



int main()

{

    solve();

}


// Faster C++ solution for the same problem (measured speedup: 1.41812308422942x):
#include <bits/stdc++.h>

#define ll long long

#define ull unsigned long long

#define pii pair<int,int>

#define piii pair<int,pii>

#define pll pair<ll,ll>

#define plii pair<ll,pii>

#define vi vector<int>

#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define SORT(x) sort(x.begin(), x.end())

#define GSORT(x) sort(x.begin(), x.end(), greater<int>())

#define mx 100001

#define eps 0.00000000001

#define mod 1000000007

#define pi acos(-1)

#define inf 100000000

#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)

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

const int N_MAX=1e5;

vector<vector<pll> >g(N_MAX);

vector<ll>color(N_MAX,0);





void dfs(ll u,ll p=-1){

    for(auto v:g[u]){

        if(v.ff==p)continue;

        if(v.ss%2)

            color[v.ff]=1-color[u];

        else

        color[v.ff]=color[u];

        dfs(v.ff,u);

    }

}

int main(){

    fio;

    ll n;

    cin >>n;

    for (int i = 0; i < n - 1; ++i) {

        ll u,v,w;

    cin >>u>>v>>w;

    u--;

    v--;

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

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

    }

    dfs(0);

    for (int i = 0; i < n; ++i) {

        cout <<color[i]<<endl;

    }

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<utility>

#include<vector>



using namespace std;



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









int ans[100000];

int n;

struct edge { int to, cost; };

vector<edge> G[100000];

void func(int e){

    rep(i, G[e-1].size()){

        if (ans[G[e-1][i].to-1] == -1) {

            if (G[e-1][i].cost % 2 == 0) {

                ans[G[e-1][i].to-1] = ans[e-1];

            }else{

                ans[G[e-1][i].to-1] = ans[e-1]^1;

            }

            func(G[e-1][i].to);

        }

    } 

}



int main(){

    // int n;

    cin >> n;

    int u[n-1], v[n-1], w[n-1];

    rep(i, n-1){

        cin >> u[i] >> v[i] >> w[i];

        edge g;

        g.cost = w[i];

        g.to = v[i];

        G[u[i]-1].push_back(g);

        g.to = u[i];

        G[v[i]-1].push_back(g);

    }



    // rep(j, n){

    //     cout << j + 1 << ";";

    //     rep(i, G[j].size()) cout << "<" << G[j][i].to << ' ' << G[j][i].cost << ">";

    //     cout << endl;

    // }

    rep(i, n) ans[i] = -1;    

    ans[0] = 0;

    func(1);



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

}

// Faster C++ solution for the same problem (measured speedup: 3.4993428522464094x):
#include<iostream>

#include<algorithm>

#include<string>

#include<vector>

#include<cstdlib>

#include<queue>

#include<cstdio>



using namespace std;



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

#define P pair<long int, long int>





int main(){

    long int n;

    cin >> n;

    long int u, v, w;

    vector<P> p[n];

    rep(i, n - 1) {

        cin >> u >> v >> w;

        u--; v--;

        p[u].push_back(P(v, w));

        p[v].push_back(P(u, w));

    }

    long int col[n];

    rep(i, n) col[i] = 0;

    col[0] = 1;

    queue<P> que;

    que.push(P(0, 0));

    while(!que.empty()){

        P g = que.front();

        que.pop();

        long int e = g.first;

        long int dis = g.second;

        for (int i = 0; i < p[e].size(); i++){

            if(col[p[e][i].first] == 0){

                long int disn = dis + p[e][i].second;

                if(disn % 2 == 0) col[p[e][i].first] = 1;

                else col[p[e][i].first] = 2;

                // cout << e << " " << p[e][i].first << " " << disn << endl;

                que.push(P(p[e][i].first, disn));

            }

        }

    }

    rep(i, n) cout << col[i] - 1 << endl;

}
// Slower C++ solution:
#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<vector>

#include <bitset>

#include<math.h>

using namespace std;

#define INF 110000000000

#define MOD 1000000007

typedef long long ll;

typedef pair<int,int> P;



int N;

vector<P> V[110000];

int color[110000];



void dfs(int x){

  for(int i=0;i<(int)V[x].size();i++){

    if(color[V[x][i].first]==-1){

      if(V[x][i].second==0){

        color[V[x][i].first]=color[x];

        dfs(V[x][i].first);

      }else{

        color[V[x][i].first]=color[x]^1;

        dfs(V[x][i].first);

      }

    } 

  }

}



int main(){

  for(int i=0;i<110000;i++) color[i]=-1;

  cin>>N;

  int u,v;

  ll w;

  for(int i=1;i<N;i++){

    cin>>u>>v>>w;

    V[u].push_back(P(v,w%2));

    V[v].push_back(P(u,w%2));

  }

  color[1]=0;

  dfs(1);

  for(int i=1;i<=N;i++) cout<<color[i]<<endl;

}


// Faster C++ solution for the same problem (measured speedup: 1.1203735706470859x):
#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<vector>

#include <bitset>

#include<math.h>

using namespace std;

#define INF 110000000000000000

#define MOD 1000000007

typedef long long ll;

typedef pair<int,ll> P;



vector<P> V[110000];

ll d[110000];

int N,u,v;





void bfs(){

  queue<P> que;



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

    d[i]=INF;

  }



  que.push(P(0,0));



  d[0]=0;



  while(que.size()){

    P p=que.front(); que.pop();

    for(int i=0;i<V[p.first].size();i++){

        P x=V[p.first][i];

      if(d[x.first]==INF){

        que.push(P(x.first,x.second+p.second));

        d[x.first]=x.second+p.second;

      }

    }

  }



  return;

}





int main(){

    cin>>N;

    ll w;

    for(int i=0;i<N-1;i++){

        cin>>u>>v>>w;

        u--; v--;

        V[u].push_back(P(v,w));

        V[v].push_back(P(u,w));

    }



    bfs();

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

        if(d[i]%2==0) cout<<0<<endl;

        else cout<<1<<endl;

    }

}
// Slower C++ solution:
#include <iostream>

#include <vector>

using namespace std;



int N;

int ans[100010] = {};

struct edge{int to, len;};

vector<vector<edge>> v(100010);



void dfs(int n,int m,int c){

    ans[n] = c;

    for(auto x:v[n]){

        if(x.to==m) continue;

        if(x.len==0) dfs(x.to,n,c);

        else dfs(x.to,n,1-c);

    }

}





int main(){

    cin >> N;

    int a,b,w;

    for(int i=0;i<N-1;i++){

        cin >> a >> b >> w;

        w %= 2;

        v[a].push_back({b,w});

        v[b].push_back({a,w});

    }

    dfs(1,0,0);

    for(int i=1;i<=N;i++) cout << ans[i] << endl;

}

// Faster C++ solution for the same problem (measured speedup: 3.479314361874403x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template <class T, class U> using Pa = pair<T, U>;

template <class T> using vec = vector<T>;

template <class T> using vvec = vector<vec<T>>;



struct edge{

    int to;

    int d;

};



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N;

    cin >> N;

    vvec<edge> g(N);

    for(int i=0;i<N-1;i++){

        int a,b,w;

        cin >> a >> b >> w;

        a--; b--;

        g[a].push_back({b,w});

        g[b].push_back({a,w});

    }

    vec<int> ans(N);

    auto dfs = [&](auto&& self,int cur,int par,int col)->void{

        ans[cur] = col;

        for(auto& e:g[cur]) if(e.to!=par){

            self(self,e.to,cur,e.d%2==0? col:1-col);

        }

    };

    dfs(dfs,0,-1,0);

    for(int i=0;i<N;i++) cout << ans[i] << "\n";

}
// Slower C++ solution:
#include <algorithm>

#include <iostream>

#include <vector>

#include <queue>

#include <set>

#include <string>

#include <map>

#include <cstring>



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

#define Rep(i, sta, n) for (int i = sta; i < (n); ++i)

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



using namespace std;

typedef long long ll;

const int mod = 1000000007;



int color[100100];

typedef pair<int, int> wedge;

vector<wedge> to[100100];



void dfs(int i, int c) {

    color[i] = c;

    for(auto e: to[i]) {

        if (color[e.first]==0 && e.second % 2 == 0) dfs(e.first, c); 

        else if (color[e.first]==0 && e.second % 2 != 0) dfs(e.first, -c); 

    }

    return;

}



int main() {

    int n;

    cin >> n;



    int u, v, w;

    rep(i, n-1) {

        cin >> u >> v >> w;

        --u, --v;

        to[u].push_back(wedge(v, w));

        to[v].push_back(wedge(u, w));

    }

    memset(color, 0, sizeof(color));

    rep(i, n) {

        if (color[i]==0) {

            dfs(i, 1);

        }

    }

    rep(i, n) {

        if (color[i]==1) cout << "0" << endl;

        else cout << "1" << endl;

    }

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.911282776902563x):
#include <algorithm>

#include <iostream>

#include <vector>

#include <queue>

#include <set>

#include <string>

#include <map>

#include <cmath>

#include <cstring>



#define fi first

#define se second

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

#define rrep(i,n) for (int i = 1; i < (n); ++i)

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

#define srep(i,s,t) for (int i = s; i < t; ++i)

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

#define maxs(x,y) (x = max(x,y))

#define mins(x,y) (x = min(x,y))

#define pb push_back

#define sz(x) (int)(x).size()

#define PQ(T) priority_queue<T, v(T), greater<T> >



using namespace std;

typedef long long ll;

typedef unsigned uint;

typedef unsigned long long ull;

typedef pair<int,int> P;



const ll LINF = 1001002003004005006ll;

const int INF = 1001001001;



const int mod = 1000000007;



struct Edge {

    int to;

    ll d;

};



int colors[100100];

bool visited[100100];

vector<vector<Edge> > es;



void dfs(int v, int p) {

    if (visited[v]) return;

    visited[v] = true;

    for (auto e: es[v]) {

        //cout << "to: " << e.to << " cost: " << e.d << endl;

        if (p == e.to) continue;



        if (e.d % 2 == 0) colors[e.to] = colors[v]; 

        else colors[e.to] = (colors[v]+1) % 2;

        dfs(e.to,v);

    }

    return;

}



int main() {

    int n; cin >> n;

    es.resize(n);



    rep(i,n-1) {

        int u, v;

        ll w;

        cin >> u >> v >> w;

        --u; --v;

        Edge edge1 = {v,w};

        es[u].pb(edge1);

        Edge edge2 = {u,w};

        es[v].pb(edge2);

    }



    dfs(0,-1);

    rep(i,n) cout << colors[i] << endl;

    return 0;

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

#define debug(x) cerr << #x << ": " << x << '\n';

using namespace std;

using ll = long long;

using P = pair<int, int>;

const int INF = (int)1e9;



struct edge{

    int to, len;

};



vector<edge> G[100000];

int N;

bool color[100000], used[100000];



void dfs(int n){

    used[n] = true;

    for(edge e: G[n]){

        if(used[e.to]) continue;

        if(e.len & 1){

            color[e.to] = not color[n];

        }else{

            color[e.to] = color[n];

        }

        dfs(e.to);

    }

}



int main(void){

    cin >> N;

    for(int i = 0; i < N-1; i++){

        int u, v, w;

        cin >> u >> v >> w; u--; v--;

        edge e; e.to = v; e.len = w;

        G[u].push_back(e);

        e.to = u;

        G[v].push_back(e);

    }



    color[0] = 0;

    dfs(0);



    for(int i = 0; i < N; i++) cout << color[i] << '\n';



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.494453974589961x):
#include <bits/stdc++.h>

#define debug(x) cerr << #x << ": " << x << '\n';

using namespace std;

using ll = long long;

using P = pair<int, int>;

const int INF = (int)1e9;

const int MOD = (int)1e9 + 7;



// graph template

template<typename T>

class Edge{

    public:

        int src, to; T cost;



        Edge(int to, T cost): src(-1), to(to), cost(cost){}

        Edge(int src, int to, T cost): src(src), to(to), cost(cost){}

};

template<typename T>

using Edges = vector<Edge<T>>;

template<typename T>

using AdjacencyList = vector<Edges<T>>;

template<typename T>

using Matrix = vector<vector<T>>;



template<typename T>

vector<bool> bipartite_matching(AdjacencyList<T> &g){

    int V = (int)g.size();

    vector<bool> color(V), used(V, false);

    

    stack<int> s;

    color[0] = false;

    s.push(0);

    while(not s.empty()){

        int v = s.top(); s.pop();

        used[v] = true;



        for(auto e: g[v]){

            if(used[e.to]){

                if((e.cost & 1) == (color[v] ^ color[e.to])) continue;

                else return vector<bool>();

            }else{

                color[e.to] = (e.cost & 1) ^ color[v];

                s.push(e.to);

            }

        }

    }



    return color;

}



int main(void){

    int N;

    cin >> N;

    AdjacencyList<int> g(N);

    for(int i = 0; i < N-1; i++){

        int u, v, w;

        cin >> u >> v >> w;

        u--; v--;

        g[u].push_back(Edge<int>(v, w));

        g[v].push_back(Edge<int>(u, w));

    }



    vector<bool> vec = bipartite_matching(g);

    if(not vec.empty()){

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

            cout << vec[i] << '\n';

        }

    }



    return 0;

}
// Slower C++ solution:
// In the name of God



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int n, c[N];

vector<pair<int,int>> adj[N];



void dfs(int u, int p, int col) {

	c[u] = col;

	for(auto v : adj[u]) {

		if(v.first == p) continue;

		dfs(v.first, u, col ^ v.second);

	}

}	



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);



	cin >> n;



	for(int i = 0; i < n - 1; i++) {

		int u, v, w;

		cin >> u >> v >> w;

		w = w & 1;

		u--;

		v--;

		adj[u].push_back(make_pair(v, w));

		adj[v].push_back(make_pair(u, w));

	}



	dfs(0, 0, 0);



	for(int i = 0; i < n; i++) cout << c[i] << "\n";



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.483555462429842x):
#include <bits/stdc++.h>

using namespace std;

#define ll long long

#define ld long double

#define vec(x) vector<x>

#define pb push_back

#define pii pair<ll,ll>

#define vi vector<ll>

#define vii vector<pair<ll,ll>>

#define matrix(x) vector<vector<x>>

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

#define mem(a,b) memset(a, b, sizeof a)

#define ff first

#define ss second

#define mp make_pair

const int INF = 1e9;

const int MOD = 1e9 + 7;



vector<vector<pair<long long,long long> > >adj;

ll n;





void bfs()

{   //ll cnt=0;

    queue<ll> q;

    vec(bool) vis(n+1,false);

    vi ans(n+1,0);

    q.push(1);

    vis[1]=true;

    ans[1]=0;

    while(!q.empty())

    {

        ll u=q.front();

        q.pop();

        //ll f=0;

        for(ll i=0;i<adj[u].size();i++)

        {  ll vff=adj[u][i].ff;

          ll vss=adj[u][i].ss;

            if(!vis[vff])

            {

                if(vss%2==0)

                    ans[vff]=ans[u];

                else

                {

                    if(ans[u]==0)

                        ans[vff]=1;

                    else

                        ans[vff]=0;

                }

                vis[vff]=true;

                q.push(vff);

            }

        }

    }

   for(ll i=1;i<n+1;i++)

   {

       printf("%lld\n",ans[i]);

   }

}



void initialize()

{

	ll i,x,y,z;

    scanf("%lld",&n);

    adj=vector<vector<pair<long long,long long> > >(n+1);



    for(i=0;i<n-1;i++)

    {

        scanf("%lld %lld %lld",&x,&y,&z);

        adj[x].pb({y,z});

        adj[y].pb({x,z});

    }

}



int32_t main()

{

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

	//ll t;

	//scanf("%lld",&t);



		initialize();

		bfs();



}
// Slower C++ solution:
// In the name of God



#include <bits/stdc++.h>



using namespace std;



const int N = 1e5+5;



int n, c[N];

vector<pair<int,int>> adj[N];



void dfs(int u, int p, int col) {

	c[u] = col;

	for(auto v : adj[u]) {

		if(v.first == p) continue;

		dfs(v.first, u, col ^ v.second);

	}

}	



int main() {

	ios_base::sync_with_stdio(false);

	cin.tie(0);



	cin >> n;



	for(int i = 0; i < n - 1; i++) {

		int u, v, w;

		cin >> u >> v >> w;

		w = w & 1;

		u--;

		v--;

		adj[u].push_back(make_pair(v, w));

		adj[v].push_back(make_pair(u, w));

	}



	dfs(0, 0, 0);



	for(int i = 0; i < n; i++) cout << c[i] << "\n";



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5108659307014967x):
#include<bits/stdc++.h>

#define ll long long int

#define ff first

#define ss second

#define eps 1e-9



using namespace std;

vector< vector<pair<ll,ll> > > g;

vector< ll> col;

vector< bool > vis;



void bfs()

{

    vis[1]=1;

    col[1]=0;

    queue<ll>  q;

    q.push(1);



    while(!q.empty())

    {

        ll top = q.front();

        q.pop();



        for(int i=0;i<g[top].size();i++)

        {

            if(vis[g[top][i].ff]==0)

            {

                vis[g[top][i].ff] =1;



                if(g[top][i].ss %2 )

                {

                    col[ g[top][i].ff ] = 1 - col[top];



                }

                else

                {

                    col[ g[top][i].ff ] = col[top];

                }



                q.push(g[top][i].ff);

            }

        }



    }

}





int main()

{



    ll t,n,m,f,a,b,c,l,r,q,k,x,y,w,z,ans,mn,mx,sum=0;



    cin>>n;



    g.resize(n+1);

    col.resize(n+1);

    vis.resize(n+1);



    for(int i=0;i<n-1;i++)

    {

        cin>>x>>y>>w;



        g[x].push_back({y,w});

        g[y].push_back({x,w});

    }



    bfs();



    for(int i=1;i<=n;i++)

    {

        cout<<col[i]<<endl;

    }









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

using namespace std;

#define ll long long

#define gcd(a,b) __gcd(a,b)

#define ff first

#define ss second

#define p pair<ll,ll>

#define pb push_back

#define endl '\n'

#define w(t) ll test;cin>>test;while(test--)

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

#define pi acos(-1)

const int mx=1e5+7;

vector<p>adj[mx];

vector<ll> vis(mx),dis(mx);

 queue<ll> q;

void bfs(ll s)

{



    q.push(s);

    vis[s]=1;

    dis[s]=0;

    while(!q.empty())

    {

        ll u=q.front();

        q.pop();

        for(auto i:adj[u])

        {

            if(!vis[i.ff])

            {

                q.push(i.ff);

                vis[i.ff]=1;

                dis[i.ff]=dis[u]+i.ss;

            }

        }

    }

}

//for a tree

int main()

{

    fast;

    ll n;

    cin>>n;

    for(int i=0;i<n-1;i++)

    {

        ll u,v,w;

        cin>>u>>v>>w;

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

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

    }

    bfs(1);

    for(int i=1;i<=n;i++)

    {

       // cout<<dis[i]<<" ";

        cout<<(dis[i]&1?1:0)<<endl;

    }

}


// Faster C++ solution for the same problem (measured speedup: 5.353417310162554x):
#include<bits/stdc++.h>

#define ll long long int

#define ff first

#define ss second

#define eps 1e-9



using namespace std;

vector< vector<pair<ll,ll> > > g;

vector< ll> col;

vector< bool > vis;



void bfs()

{

    vis[1]=1;

    col[1]=0;

    queue<ll>  q;

    q.push(1);



    while(!q.empty())

    {

        ll top = q.front();

        q.pop();



        for(int i=0;i<g[top].size();i++)

        {

            if(vis[g[top][i].ff]==0)

            {

                vis[g[top][i].ff] =1;



                if(g[top][i].ss %2 )

                {

                    col[ g[top][i].ff ] = 1 - col[top];



                }

                else

                {

                    col[ g[top][i].ff ] = col[top];

                }



                q.push(g[top][i].ff);

            }

        }



    }

}





int main()

{



    ll t,n,m,f,a,b,c,l,r,q,k,x,y,w,z,ans,mn,mx,sum=0;



    cin>>n;



    g.resize(n+1);

    col.resize(n+1);

    vis.resize(n+1);



    for(int i=0;i<n-1;i++)

    {

        cin>>x>>y>>w;



        g[x].push_back({y,w});

        g[y].push_back({x,w});

    }



    bfs();



    for(int i=1;i<=n;i++)

    {

        cout<<col[i]<<endl;

    }









}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<map>

#include<algorithm>

#include<cmath>

#include<string>

#include<cstdlib>

#include<iomanip>



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

#define REP(i,n)   FOR(i,0,n)

#define MOD 1000000007



using namespace std;



typedef long long int ll;



const ll INF=(ll)1e18;



vector<vector<pair<int,ll> > > d(100001);



int color[100001];

bool visited[100001];



void dfs(int n, int col){

//  printf("%d %d\n",n,col);

  if(visited[n])return;

  visited[n] = true;

  color[n]=col;

  int col2 = col == 0 ? 1 : 0;



  REP(i,d[n].size()){

    if(d[n][i].second % 2 == 0){

      dfs(d[n][i].first, col);

    }else{

      dfs(d[n][i].first, col2);

    }

  }

}



int main(){



  int N;

  cin >> N;





  REP(i,N-1){

    int u,v;

    ll w;

    cin >> u >> v >> w;

    d[u].push_back(make_pair(v,w));

    d[v].push_back(make_pair(u,w));

  }



  // FOR(i,1,N+1){

  //   cout << i << endl;

  //   REP(j,d[i].size()){

  //     printf("%d %lld\n", d[i][j].first,d[i][j].second);

  //   }

  // }



  FOR(i,1,N+1)visited[i]=false;



  dfs(1,0);



  FOR(i,1,N+1){

    cout << color[i] << endl;

  }



}


// Faster C++ solution for the same problem (measured speedup: 3.52046249220555x):
#include <bits/stdc++.h>

using namespace std;



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

#define REP(i,n)   FOR(i,0,n)

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

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

#define PRINT(a)   cout << (a) << endl



#define pb push_back

#define eb emplace_back

#define mp make_pair

#define Fi first

#define Se second



#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';



using ll = long long int;

using P = pair<int,int>;

using vi = vector<int>;

using vvi = vector<vi>;

using vvvi = vector<vvi>;

using pii = pair<int, int>;



template <typename T> using PQ = priority_queue<T>;

template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;



template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



const int INF = 1001001001;

const ll LINF = 1001001001001001001ll;

const int MOD = 1e9 + 7;



int main(){

  int N;

  cin >> N;



  vector<vector<P>> edge(N);

  vi col(N,-1);



  REP(i,N-1){

    int u,v,w;

    cin >> u >> v >> w;

    u--; v--;

    edge[u].emplace_back(v,w);

    edge[v].emplace_back(u,w);

  }



  queue<P> q;

  col[0]=0;

  q.emplace(0,0);



  while(!q.empty()){

    int x = q.front().first;

    int c = q.front().second;

    q.pop();



    for(auto e: edge[x]){

      int y = e.first;

      int w = e.second;

      if(col[y]!=-1)continue;



      if(w%2==0){

        col[y] = c;

      }else{

        col[y] = c ^ 1;

      }

      q.emplace(y, col[y]);

    }

  }



  REP(i,N){

    cout << col[i] << endl;

  }

}