Language: C++

#include <bits/stdc++.h>
using namespace std;

constexpr int MAX_N = 1e5 + 7;

int N;
int edges[MAX_N+1][MAX_N+1];
int colors[MAX_N+1];

void dfs(int prev, int cur) {
  colors[cur] = edges[prev][cur] % 2 == 0 ? colors[prev] : !colors[prev];

  for (int i{1}; i <= N; ++i) {
    if (i == prev || colors[i] >= 0)
      continue;
    dfs(cur, i);
  }
}

int main() {
  fill_n(colors, colors + MAX_N+1, -1);
  colors[0] = 0;

  cin >> N;

  int u, v, w;
  for (int i{}; i < N - 1; ++i) {
    cin >> u >> v >> w;
    edges[u][v] = edges[v][u] = w;
  }

  dfs(0, u);
  for (int i{1}; i <= N; ++i) {
    cout << colors[i] << endl;
  }
}


Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of '_OI std::fill_n(_OI, _Size, const _Tp&) [with _OI = int*; _Size = int*; _Tp = int]':
a.cc:21:9:   required from here
   21 |   fill_n(colors, colors + MAX_N+1, -1);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1183:61: error: no matching function for call to '__size_to_integer(int*&)'
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:1036:3: note: candidate: 'constexpr int std::__size_to_integer(int)' (near match)
 1036 |   __size_to_integer(int __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1036:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to 'int' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1038:3: note: candidate: 'constexpr unsigned int std::__size_to_integer(unsigned int)' (near match)
 1038 |   __size_to_integer(unsigned __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1038:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to 'unsigned int' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1040:3: note: candidate: 'constexpr long int std::__size_to_integer(long int)' (near match)
 1040 |   __size_to_integer(long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1040:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to 'long int' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1042:3: note: candidate: 'constexpr long unsigned int std::__size_to_integer(long unsigned int)' (near match)
 1042 |   __size_to_integer(unsigned long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1042:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to 'long unsigned int' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1044:3: note: candidate: 'constexpr long long int std::__size_to_integer(long long int)' (near match)
 1044 |   __size_to_integer(long long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1044:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to 'long long int' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1046:3: note: candidate: 'constexpr long long unsigned int std::__size_to_integer(long long unsigned int)' (near match)
 1046 |   __size_to_integer(unsigned long long __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1046:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to 'long long unsigned int' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1050:3: note: candidate: 'constexpr __int128 std::__size_to_integer(__int128)' (near match)
 1050 |   __size_to_integer(__GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1050:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to '__int128' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1052:3: note: candidate: 'constexpr __int128 unsigned std::__size_to_integer(__int128 unsigned)' (near match)
 1052 |   __size_to_integer(unsigned __GLIBCXX_TYPE_INT_N_0 __n) { return __n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1052:3: note:   conversion of argument 1 would be ill-formed:
/usr/include/c++/14/bits/stl_algobase.h:1183:62: error: invalid conversion from 'int*' to '__int128 unsigned' [-fpermissive]
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |                                                              ^~~
      |                                                              |
      |                                                              int*
/usr/include/c++/14/bits/stl_algobase.h:1074:3: note: candidate: 'constexpr long long int std::__size_to_integer(float)'
 1074 |   __size_to_integer(float __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1074:27: note:   no known conversion for argument 1 from 'int*' to 'float'
 1074 |   __size_to_integer(float __n) { return (long long)__n; }
      |                     ~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1076:3: note: candidate: 'constexpr long long int std::__size_to_integer(double)'
 1076 |   __size_to_integer(double __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1076:28: note:   no known conversion for argument 1 from 'int*' to 'double'
 1076 |   __size_to_integer(double __n) { return (long long)__n; }
      |                     ~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1078:3: note: candidate: 'constexpr long long int std::__size_to_integer(long double)'
 1078 |   __size_to_integer(long double __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1078:33: note:   no known conversion for argument 1 from 'int*' to 'long double'
 1078 |   __size_to_integer(long double __n) { return (long long)__n; }
      |                     ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_algobase.h:1081:3: note: candidate: 'constexpr long long int std::__size_to_integer(__float128)'
 1081 |   __size_to_integer(__float128 __n) { return (long long)__n; }
      |   ^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1081:32: note:   no known conversion for argument 1 from 'int*' to '__float128'
 1081 |   __size_to_integer(__float128 __n) { return (long long)__n; }
      |                     ~~~~~~~~~~~^~~