Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;

ll flg[11451411919];
vector<ll > G[11451411919];
vector<ll > ans;
vector<vector<ll > > weight;
//flg = 1 すでに到達済み 0＝まだ到達していない
void dfs(ll idx, ll from = -1){
    /*
    ll f = 1;
    if(flg[idx] == 1){
        return 0;
    }
    */

    //参照したので到達済みフラグを１にする
    //flg[idx] = 1;

    for(ll i = 0; i < G[idx].size(); i++){
        //次の行き先は？
        ll to = G[idx][i];
        //同じだったらもう処理しない
        //頂点に戻ってきたら
        if(to == from){
            continue;
        }

        if(weight[idx][to] % 2 == 0){
            if(ans[to] == -1){
                ans[to] = ans[idx];
            }
        }else{
            if(ans[to] == -1){
                ans[to] = (ans[idx] + 1) % 2;
            }            
        }

        //ans[to] += ans[idx];
        dfs(to, idx);
        //閉路は無い想定なので不要！
        //from = idx > toへ
        //もしすでに到達済みの場所を参照したら、木ではなく閉路のある無向グラフ
        /*
        if(dfs(to, idx) == 1){
            //閉路ですよ
            f = 0;
        }
        */
    }
    //1が帰ったら木ですよ
    /* 
    return f;
    */

}

int main(){

    ll N;
    cin >> N;
    ans.resize(N);
    //初期化
    ans[0] = 0;
    for(ll i = 1; i < N; i++){
        ans[i] = -1;
    }
    //vector<vector<ll > > weight(N, vector<ll >(N, 0));
    weight.resize(N, vector<ll >(N));
    //グラフを貼ります(今回は木)
    vector<ll > u(N-1);
    vector<ll > v(N-1);
    for(ll i = 0; i < N-1; i++){
        ll wg  = 0;
        cin >> u[i];
        cin >> v[i];
        cin >> wg;
        u[i]--;
        v[i]--;
        //双方向に貼りましょうね
        G[u[i]].push_back(v[i]);
        G[v[i]].push_back(u[i]);
        //重みも双方向に貼りましょうね〜ウェイ！
        weight[u[i]][v[i]] = wg;
        weight[v[i]][u[i]] = wg;
    }
    //あるノードからそれ以下のノードに流し込むコストをどんどん加算していく
    /*
    for(ll i = 0; i < Q; i++){
        ll p, x;
        cin >> p >> x;
        ans[p-1] += x;
    }
    */

    //伝搬実行
    dfs(0);
    for(ll i = 0; i < N; i++){
        cout << ans[i] << endl;;
    }

}

Compiler output:
/tmp/ccccNiVm.o: in function `dfs(long long, long long)':
a.cc:(.text+0x32): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0x67): relocation truncated to fit: R_X86_64_PC32 against symbol `weight' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0x9f): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0xc7): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0xe0): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0xfb): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0x11f): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0x153): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0x191): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccccNiVm.o
/tmp/ccccNiVm.o: in function `main':
a.cc:(.text+0x1e8): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccccNiVm.o
a.cc:(.text+0x1fc): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status