Language: C++

#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;//thisポインター　thisで自分自身のアドレス
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
*/


int used[110000];
int color[110000];
vector<vector<int> > to(110000);
int cost[110000][110000];

void dfs(int k){
    rep(i,to[k].size()){
        if(used[to[k][i]]==0){
            qu.push(to[k][i]);
            used[to[k][i]]=1;
        }
    }
    if(!qu.empty()){
        int v=qu.front();
        qu.pop();
        rep(i,to[v].size()){
            int u=to[v][i];
            int w=cost[v][u];
            if(used[u]==1){
                continue;
            }else{
                used[u]=1;
                color[u]=(color[v]+w)%2;
                qu.push(u);
            }
        }
        
        //cout<<v<<endl;
    }
    return ;
}

int main(){
    int n;
    cin >> n;
    
    rep(i,n-1){
        int u,v,w;
        cin >> u>> v >> w;
        u--;v--;
        to[u].push_back(v);
        to[v].push_back(u);
        cost[u][v]=w%2;
        cost[v][u]=w%2;
    }
    color[0]=0;
    used[0]=1;
    dfs(0);
    rep(i,n){
        cout<<color[i]<<endl;
    }
    //cout<<cost[1][2]<<endl;
    return 0;
}


Compiler output:
/tmp/ccmvTPG8.o: in function `__gnu_debug::_Error_formatter::_S_at(char const*, unsigned int, char const*)':
a.cc:(.text._ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_[_ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_]+0x16): relocation truncated to fit: R_X86_64_PC32 against symbol `guard variable for __gnu_debug::_Error_formatter::_S_at(char const*, unsigned int, char const*)::__formatter' defined in .bss._ZGVZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter[_ZGVZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter] section in /tmp/ccmvTPG8.o
a.cc:(.text._ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_[_ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_]+0x26): relocation truncated to fit: R_X86_64_PC32 against symbol `guard variable for __gnu_debug::_Error_formatter::_S_at(char const*, unsigned int, char const*)::__formatter' defined in .bss._ZGVZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter[_ZGVZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter] section in /tmp/ccmvTPG8.o
a.cc:(.text._ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_[_ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_]+0x4c): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_debug::_Error_formatter::_S_at(char const*, unsigned int, char const*)::__formatter' defined in .bss._ZZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter[_ZZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter] section in /tmp/ccmvTPG8.o
a.cc:(.text._ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_[_ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_]+0x5b): relocation truncated to fit: R_X86_64_PC32 against symbol `guard variable for __gnu_debug::_Error_formatter::_S_at(char const*, unsigned int, char const*)::__formatter' defined in .bss._ZGVZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter[_ZGVZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter] section in /tmp/ccmvTPG8.o
a.cc:(.text._ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_[_ZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_]+0x6a): relocation truncated to fit: R_X86_64_PC32 against symbol `__gnu_debug::_Error_formatter::_S_at(char const*, unsigned int, char const*)::__formatter' defined in .bss._ZZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter[_ZZN11__gnu_debug16_Error_formatter5_S_atEPKcjS2_E11__formatter] section in /tmp/ccmvTPG8.o
collect2: error: ld returned 1 exit status