#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/*
 * Let B = 1, W = 0; assume node 1 is colored as B. At any node we can
 * color it either B or W if the constraint is not violated. We can use
 * the distance to the root to decide if the constraint is met.
 */

const int maxn = 1e5+5;
/*
 * dp(i,j)
 * i - ith node
 * j - 0 white node dist to root is even
 *     1 white node dist to root is odd
 *     2 there is no white node (we always color the root to black)
 */
int dist[maxn], res[maxn], dp[maxn][3];
VI G[maxn]; map<PII,int> W;

int dfs(const int u, const int p, const int pc, const int wc)
{
    int& ans = dp[u][wc];
    if (-1 == ans) {
        ans = 0;
        const int w = W[PII(u,p)];
        dist[u] = (dist[p]+w) % 2;
        if (!dist[u]) {         /* color u to B */
            ans = 1; res[u] = 1;
            FOR_ALL(v,G[u]) if (*v != p)
                ans &= dfs(*v,u,1,wc);
        }
        if (!ans) {             /* color u to W */
            if (wc==2 || (!wc && !dist[u]) || (wc && dist[u])) {
                ans = 1; res[u] = 0;
                FOR_ALL(v,G[u]) if (*v != p)
                    ans &= dfs(*v,u,0,dist[u]);
            }
        }
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        FOR(i,1,n+1)
            G[i].clear();
        FOR(_,0,n-1) {
            int u,v,w; cin >> u >> v >> w;
            w %= 2;
            G[u].push_back(v);
            G[v].push_back(u);
            W[PII(u,v)] = W[PII(v,u)] = w;
        }
        memset(dp,-1,sizeof(dp));
        dist[1] = 0; res[1] = 1;
        FOR_ALL(v,G[1])
            dfs(*v,1,1,2);
        FOR(i,1,n+1)
            cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 25472