Problem p03044 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \
  {                                                                            \
    REP(WW, n) cerr << v[WW] << ' ';                                           \
    cerr << endl << endl;                                                      \
  }
#define SHOW2d(v, WW, HH)                                                      \
  {                                                                            \
    REP(W_, WW) {                                                              \
      REP(H_, HH) cerr << v[W_][H_] << ' ';                                    \
      cerr << endl;                                                            \
    }                                                                          \
    cerr << endl;                                                              \
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll, ll> P;

vector<vector<P>> v(11111);
int out[111111];

void dfs(int now, int pre) {
  REP(i, v[now].size()) {
    if (v[now][i].FI == pre)
      continue;
    if (v[now][i].SE % 2) {
      out[v[now][i].FI] = 1 - out[now];
    } else {
      out[v[now][i].FI] = out[now];
    }
    dfs(v[now][i].FI, now);
  }
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n - 1) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v[a].EB(b, c);
    v[b].EB(a, c);
  }

  dfs(0, -1);

  REP(i, n) cout << out[i] << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n)                                                           \
  {                                                                            \
    REP(WW, n) cerr << v[WW] << ' ';                                           \
    cerr << endl << endl;                                                      \
  }
#define SHOW2d(v, WW, HH)                                                      \
  {                                                                            \
    REP(W_, WW) {                                                              \
      REP(H_, HH) cerr << v[W_][H_] << ' ';                                    \
      cerr << endl;                                                            \
    }                                                                          \
    cerr << endl;                                                              \
  }
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll, ll> P;

vector<vector<P>> v(111111);
int out[111111];

void dfs(int now, int pre) {
  REP(i, v[now].size()) {
    if (v[now][i].FI == pre)
      continue;
    if (v[now][i].SE % 2) {
      out[v[now][i].FI] = 1 - out[now];
    } else {
      out[v[now][i].FI] = out[now];
    }
    dfs(v[now][i].FI, now);
  }
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  REP(i, n - 1) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    v[a].EB(b, c);
    v[b].EB(a, c);
  }

  dfs(0, -1);

  REP(i, n) cout << out[i] << endl;

  return 0;
}