Problem p03044 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define jh(x, y) x ^= y ^= x ^= y
#define loc(x, y) (x - 1) * m + y
#define rg register
#define inl inline
#define PI 3.141592654
typedef long long ll;
const int N = 6e2 + 5, INF = 0x3f3f3f3f, mod = 998244353;
using namespace std;
namespace fast_IO {
inl ll read() {
  rg char c;
  rg ll x = 0;
  rg bool flag = false;
  while ((c = getchar()) == ' ' || c == '\n' || c == '\r')
    ;
  if (c == EOF)
    return c;
  if (c == '-')
    flag = true;
  else
    x = c ^ 48;
  while ((c = getchar()) != ' ' && c != '\n' && c != '\r' && ~c)
    x = (x << 1) + (x << 3) + (c ^ 48);
  if (flag)
    return -x;
  return x;
}
inl ll max(rg ll a, rg ll b) {
  if (a > b)
    return a;
  return b;
}
inl ll min(rg ll a, rg ll b) {
  if (a < b)
    return a;
  return b;
}
void write(rg ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 ^ 48);
}
} // namespace fast_IO
int p[N], b[N], nt[N], w[N], c[N], num;
inl void add(rg int z, rg int y, rg int x) {
  b[++num] = y, w[num] = z;
  nt[num] = p[x], p[x] = num;
  b[++num] = x, w[num] = z;
  nt[num] = p[y], p[y] = num;
}
void dfs(rg int x, rg int fa) {
  for (rg int e = p[x]; e; e = nt[e]) {
    if (b[e] == fa)
      continue;
    c[b[e]] = c[x] ^ (w[e] & 1);
    dfs(b[e], x);
  }
}

int main(void) {
  rg int n = fast_IO::read();
  for (rg int i = 1; i < n; ++i)
    add(fast_IO::read(), fast_IO::read(), fast_IO::read());
  c[1] = 1;
  dfs(1, 0);
  for (rg int i = 1; i <= n; ++i)
    fast_IO::write(c[i]), putchar('\n');
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define jh(x, y) x ^= y ^= x ^= y
#define loc(x, y) (x - 1) * m + y
#define rg register
#define inl inline
#define PI 3.141592654
typedef long long ll;
const int N = 6e5 + 5, INF = 0x3f3f3f3f, mod = 998244353;
using namespace std;
namespace fast_IO {
inl ll read() {
  rg char c;
  rg ll x = 0;
  rg bool flag = false;
  while ((c = getchar()) == ' ' || c == '\n' || c == '\r')
    ;
  if (c == EOF)
    return c;
  if (c == '-')
    flag = true;
  else
    x = c ^ 48;
  while ((c = getchar()) != ' ' && c != '\n' && c != '\r' && ~c)
    x = (x << 1) + (x << 3) + (c ^ 48);
  if (flag)
    return -x;
  return x;
}
inl ll max(rg ll a, rg ll b) {
  if (a > b)
    return a;
  return b;
}
inl ll min(rg ll a, rg ll b) {
  if (a < b)
    return a;
  return b;
}
void write(rg ll x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 ^ 48);
}
} // namespace fast_IO
int p[N], b[N], nt[N], w[N], c[N], num;
inl void add(rg int z, rg int y, rg int x) {
  b[++num] = y, w[num] = z;
  nt[num] = p[x], p[x] = num;
  b[++num] = x, w[num] = z;
  nt[num] = p[y], p[y] = num;
}
void dfs(rg int x, rg int fa) {
  for (rg int e = p[x]; e; e = nt[e]) {
    if (b[e] == fa)
      continue;
    c[b[e]] = c[x] ^ (w[e] & 1);
    dfs(b[e], x);
  }
}

int main(void) {
  rg int n = fast_IO::read();
  for (rg int i = 1; i < n; ++i)
    add(fast_IO::read(), fast_IO::read(), fast_IO::read());
  c[1] = 1;
  dfs(1, 0);
  for (rg int i = 1; i <= n; ++i)
    fast_IO::write(c[i]), putchar('\n');
  return 0;
}