Language: C++

#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

vector<vector<pair<LL, LL>>> edge(100000);
vector<LL> a(100000, -1);
vector<LL> parent(100000, -1);
vector<vector<LL>> children(100000);
vector<int> xor (100000, 0);

void make_graph(LL start, LL weight) {
	a[start] = weight;
	REP(i, edge[start].size()) {
		if (a[edge[start][i].first] == -1) {
			parent[edge[start][i].first] = start;
			children[start].push_back(edge[start][i].first);
			make_graph(edge[start][i].first, edge[start][i].second);
		}
	}
}

int find_ans(LL start) {
	int xor_sum = a[start];
	REP(i, children[start].size()) {
		int xor_num = find_ans(children[start][i]);
		xor_sum = xor_sum ^ xor_num;
	}
	xor[start] = xor_sum & 15;
	return xor[start];
}

int main() {
	LL N;
	cin >> N;

	REP(i, N - 1) {
		LL x, y, a;
		cin >> x >> y >> a;
		edge[x].push_back(make_pair(y, a));
		edge[y].push_back(make_pair(x, a));
	}

	make_graph(0, -2);

	find_ans(0);

	vector<LL> num(4, 0);
	FOR(i,1, xor.size()) {
		num[0] += (xor[i] & 1) / 1;
		num[1] += (xor[i] & 2) / 2;
		num[2] += (xor[i] & 4) / 4;
		num[3] += (xor[i] & 8) / 8;
	}

	LL sum = 0;
	REP(i, num.size()) {
		sum += (num[i] + 1) / 2;
	}

	cout << sum << endl;
}

Compiler output:
a.cc:48:13: error: expected unqualified-id before 'xor' token
   48 | vector<int> xor (100000, 0);
      |             ^~~
a.cc: In function 'int find_ans(LL)':
a.cc:67:9: error: expected primary-expression before 'xor' token
   67 |         xor[start] = xor_sum & 15;
      |         ^~~
a.cc: In lambda function:
a.cc:67:20: error: expected '{' before '=' token
   67 |         xor[start] = xor_sum & 15;
      |                    ^
a.cc: In function 'int find_ans(LL)':
a.cc:68:16: error: expected primary-expression before 'xor' token
   68 |         return xor[start];
      |                ^~~
a.cc: In lambda function:
a.cc:68:26: error: expected '{' before ';' token
   68 |         return xor[start];
      |                          ^
a.cc: In function 'int main()':
a.cc:87:18: error: expected primary-expression before 'xor' token
   87 |         FOR(i,1, xor.size()) {
      |                  ^~~
a.cc:41:36: note: in definition of macro 'FOR'
   41 | #define FOR(i,a,b) for(LL i=(a);i<(b);++i)
      |                                    ^
a.cc:87:21: error: expected primary-expression before '.' token
   87 |         FOR(i,1, xor.size()) {
      |                     ^
a.cc:41:36: note: in definition of macro 'FOR'
   41 | #define FOR(i,a,b) for(LL i=(a);i<(b);++i)
      |                                    ^
a.cc:88:28: error: expected primary-expression before 'xor' token
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                            ^~~
a.cc: In lambda function:
a.cc:88:35: error: expected '{' before '&' token
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                   ^
a.cc: In function 'int main()':
a.cc:88:35: error: no match for 'operator&' (operand types are 'main()::<lambda()>' and 'int')
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                               ~~~ ^ ~
      |                               |     |
      |                               |     int
      |                               main()::<lambda()>
In file included from /usr/include/c++/14/valarray:605,
                 from a.cc:18:
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   'main()::<lambda()>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   'main()::<lambda()>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   'main()::<lambda()>' is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/bits/valarray_after.h:411:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__bitwise_and, typename _Dom1::value_type>::result_type> std::operator&(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)'
  411 |     _DEFINE_EXPR_BINARY_OPERATOR(&, struct std::__bitwise_and)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:411:5: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/valarray:1202:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__bitwise_and, _Tp>::result_type> std::operator&(const valarray<_Tp>&, const valarray<_Tp>&)'
 1202 | _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1202:1: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   'main()::<lambda()>' is not derived from 'const std::valarray<_Tp>'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/valarray:1202:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__bitwise_and, _Tp>::result_type> std::operator&(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)'
 1202 | _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1202:1: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   'main()::<lambda()>' is not derived from 'const std::valarray<_Tp>'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
/usr/include/c++/14/valarray:1202:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__bitwise_and, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__bitwise_and, _Tp>::result_type> std::operator&(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)'
 1202 | _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/valarray:1202:1: note:   template argument deduction/substitution failed:
a.cc:88:37: note:   mismatched types 'const std::valarray<_Tp>' and 'int'
   88 |                 num[0] += (xor[i] & 1) / 1;
      |                                     ^
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/cstddef:141:3: note: candidate: 'constexpr std::byte std::operator&(byte, byte)'
  141 |   operator&(byte __l, byte __r) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/cstddef:141:18: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'std::byte'
  141 |   operator&(byte __l, byte __r) noexcept
      |             ~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:84:3: note: candidate: 'constexpr std::_Ios_Fmtflags std::operator&(_Ios_Fmtflags, _Ios_Fmtflags)'
   84 |   operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:84:27: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'std::_Ios_Fmtflags'
   84 |   operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:134:3: note: candidate: 'constexpr std::_Ios_Openmode std::operator&(_Ios_Openmode, _Ios_Openmode)'
  134 |   operator&(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:134:27: note:   no known conversion for argument 1 from 'main()::<lambda()>' to 'std::_Ios_Openmode'
  134 |   operator&(_Ios_Openmode __a, _Ios_Openmode __b) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:181:3: note: candidate: 'constexpr std::_Ios_Iostate std::operator&(_Ios_Iostate, _Ios_Iostate)'
  181 |   operator&(_Ios_Iostate __a, _Ios_Iostate __b) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:181:26: note:   no