#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T, typename U, typename V>
ostream &operator<<(ostream &os, const tuple<T, U, V> &t){
  os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef tuple<int, int, int> TT;
typedef pair<int, TT> PT;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);





vector<pair<int, int>> G[200000];    // 辺 G[i] = P(j, w): i番目の頂点からj番目の頂点へコストwの辺をはる
int d[200000];    // d[i]: i番目の頂点の色(d[i]=0:無色, d[i]=1:白, d[i]=2:黒)

// dfs(u, s): 頂点uの処理(s=0なら白色に塗る, s=1なら黒色に塗る)
void dfs(int u, int s){
  if(s == 0)d[u] = 1;
  else d[u] = 2;
  // 隣接した頂点が無色ならその頂点に移動して、適した色を塗る
  rep(i,G[u].size()){
    pair<int, int> p = G[u][i];    // p = (p.first, p.second) = (行先の頂点番号, コスト)
    if(d[p.first] != 0)continue;   // 無色でなければ移動しない
    dfs(p.first, (s+p.second)%2);    // コストが奇数なら今いる頂点と違う色、偶数なら同じ色で塗る
  }
  return;   // 隣接する頂点を塗り終わったらreturn
}
 
signed main(){
  int n;cin >> n;
  rep(i,n-1){
    int u, v, w;cin >> u >> v >> w;
    G[u].pb(make_pair(v, w));
    G[v].pb(make_pair(u, w));
  }
  
  // 頂点1からdfsする(頂点1は白色に塗る)
  // dfsはどこの頂点から始めてもいいし何色(白か黒)で始めてもいい
  dfs(1, 0);
  rrep(i,n)cout << d[i]-1 << endl;
  return 0;
}






Measured memory_bytes: 12544