Language: C++

#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)					// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif

namespace NyaGadgetUnionFind
{
	struct Edge
	{	// 辺を表現する構造体
		ll v1;
		ll v2;
	};

	struct Vertex
	{	// 頂点を表現する構造体
		ll root;
		ll size;
	};

	template <class E, class V> struct Graph
	{	// グラフを表現する構造体
		vector<E> edge;
		vector<V> vertex;
		Graph(vector<E>& e, vector<V> v)
		{	// グラフ構造を構造体に格納する
			edge.resize(e.size());
			vertex.resize(v.size());
			swap(e, edge);
			swap(v, vertex);
			ll v_index = 0;
			for (auto& v : vertex)
			{	// 各頂点の根を自分自身で初期化、各頂点の木サイズは１で初期化
				v.root = v_index++;
				v.size = 1;
			}
		}
		ll FindRoot(ll v_index)
		{
			// 自分自身が根のとき
			if (v_index == vertex[v_index].root)
				return vertex[v_index].root;
			// 根の探索をすると同時に次からO(1)で根を参照できるようにする
			return vertex[v_index].root = FindRoot(vertex[v_index].root);
		}
		void UnionTree(ll v1_index, ll v2_index)
		{
			ll tree1_root = FindRoot(v1_index);
			ll tree2_root = FindRoot(v2_index);

			// サイズの小さい木の根をサイズの大きい木の根に繋いで結合する
			if (vertex[tree1_root].size < vertex[tree2_root].size)
			{
				vertex[tree1_root].root = tree2_root;
				vertex[tree2_root].size += vertex[tree1_root].size;
			}
			else
			{
				vertex[tree2_root].root = tree1_root;
				vertex[tree1_root].size += vertex[tree2_root].size;
			}
		}
	};
}

using namespace NyaGadgetUnionFind;

struct ExEdge : public Edge
{
	ll cost;
	bool operator < (const ExEdge& e) const
	{
		return v1 < e.v1;
	}
	bool operator > (const ExEdge& e) const
	{
		return v1 > e.v1;
	}
};

using namespace NyaGadgetUnionFind;

struct ExEdge : public Edge
{
	ll cost;
	bool operator < (const ExEdge& e) const
	{
		return v1 < e.v1;
	}
	bool operator > (const ExEdge& e) const
	{
		return v1 > e.v1;
	}
};

class ABC126D
{
public:
    ABC126D()
    {
        cin >> n;
        edge.resize(n-1);
        vertex.resize(n);
        
        rep(ei, 0, n-1)
		{
            cin >> edge[ei].v1 >> edge[ei].v2 >> edge[ei].cost;
			edge[ei].v1--;
			edge[ei].v2--;
		}
			
    }
    void Run(void)
    {
        sort(all(edge));
        Graph <ExEdge, Vertex> graph(edge, vertex);
        
        rep(ei, 0, n-1)
        {
			ExEdge e = graph.edge[ei];
            if (e.cost % 2 == 0)
				graph.UnionTree(e.v1, e.v2);
        }

		vector<ll> ans(n);
		ll value01 = 0;
		rep(vi, 0, n)
		{
			if (graph.vertex[graph.FindRoot(vi)].size == 1)
				value01 = (value01 == 0) ? 1 : 0;
			ans[vi] = value01;
		}
		
		for(const auto &e : ans)
			cout << e << endl;
    }
private:
	ll n;
	vector<ExEdge> edge;
	vector<Vertex> vertex;
};

int main(void)
{
	ABC126D abc126d;
	abc126d.Run();
	
	return 0;
}


Compiler output:
a.cc:178:8: error: redefinition of 'struct ExEdge'
  178 | struct ExEdge : public Edge
      |        ^~~~~~
a.cc:163:8: note: previous definition of 'struct ExEdge'
  163 | struct ExEdge : public Edge
      |        ^~~~~~