#pragma region include
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <map>
    #include <string>
    #include <queue>
    #include <stack>
    #include <cmath>
    #include <set>
    #include <cstdio>
    #define ALL(obj) (obj).begin(),(obj).end()
    #define RALL(obj) (obj).rbegin(),(obj).rend()
    #define REP(i, n) for(int i = 0; i < n; i++)
    #define REPR(i, n) for(int i = n; i >= 0; i--)
    #define FOR(i, m, n) for(int i = m; i < n; i++)
    #define MOD 1000000007
    #define INF 1000000000
    #define LLINF 4000000000000000000
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> PII;
    typedef vector<int> VI;
    typedef vector<VI> VVI;
    #pragma endregion
     
    //#define __DEBUG__
    #ifdef  __DEBUG__
    #define dump(x) cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
    // vector出力
    template<typename T>
    ostream& operator << (ostream& os, vector<T>& v) {
        os << "{";
        REP(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
        os << "}";
        return os;
    }
    // pair出力
    template<typename T, typename U>
    ostream& operator << (ostream& os, pair<T, U>& p) {
        return os << "(" << p.first << ", " << p.second << ")";
    }
    // map出力
    template<typename T, typename U>
    ostream& operator << (ostream& os, map<T, U>& map_var) {
        os << "{";
        for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
            os << "(" << itr->first << ", " << itr->second << ")";
            itr++;
            if (itr != map_var.end()) os << ", ";
            itr--;
        }
        os << "}";
        return os;
    }
    // set 出力
    template<typename T>
    ostream& operator << (ostream& os, set<T>& set_var) {
        os << "{";
        for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
            os << *itr;
            ++itr;
            if (itr != set_var.end()) os << ", ";
            itr--;
        }
        os << "}";
        return os;
    }
    #endif
     
    struct Edge {
        int to, cost;
    };
     
    int main() {
        cin.tie(0); ios::sync_with_stdio(false);
        int N; cin >> N;
        vector<vector<Edge>> tree(N,vector<Edge>());
        vector<bool> visited(N, false);
        VI ans(N,-1);
        REP(i, N-1) {
            int u, v, w;
            cin >> u >> v >> w;
            u--; v--;
            tree[u].emplace_back(Edge{v,w});
            tree[v].emplace_back(Edge{u,w});
        }
        queue<PII> que;
        ans[0] = 0;
        visited[0] = true;
        que.push(PII(0,0));
        while (!que.empty()) {
            PII q = que.front(); que.pop();
            ans[q.first] = q.second;
            for (int i = 0; i < tree[q.first].size(); i++)
            {
                if (!visited[tree[q.first][i].to]) {
                    if (tree[q.first][i].cost % 2 == 0) {
                        que.push(PII(tree[q.first][i].to, q.second));
                    }
                    else {
                        que.push(PII(tree[q.first][i].to, 1 - q.second));
                    }
                    visited[tree[q.first][i].to] = true;
                }
            }
        }
        REP(i, N) {
            cout << ans[i] << endl;
        }
        getchar(); getchar();
    }

Measured memory_bytes: 6912