Language: C++

#include "iostream"
#include "cstring"
#include "cstdio"
#include "set"
#include "map"
#include "algorithm"
#include "vector"
#include "queue"
#include "cassert"
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
typedef long long ll;
typedef pair<int, int> PII;
const int N = 100010;

vector<PII> e[N];
vector<int> node;
int balence[N], visit[N], size[N];
void dfs(int x, int fa)
{
	size[x] = 1;
	balence[x] = 0;
	for(int i = 0; i < e[x].size(); ++ i){
		int u = e[x][i].F;
		if(u == fa || visit[u]) continue;
		dfs(u);
		size[x] += size[u];
		balence[x] = max(balence[x], size[u]);
	}
	node.PB(x);
}

int GetRoot(int x)
{
	dfs(x, -1);
	node.clear();
	int total = size[x];
	int root = node[0];
	int val = max(balence[root], total - size[root]);
	for(int i = 1; i < node.size(); ++ i){
		int u = node[i];
		int tmp = max(balence[u], total - size[u]);
		if(tmp < val){
			val = tmp;
			root = u;
		}
	}
	return root;
}
long long ans = 0;
map<int, int> mp;
void dfs2(int x, int pa, int depth)
{
	mp[depth] ++;
	
void solve(int x)
{
	visit[x] = 1;
	int root = GetRoot(x);
	dfs2(root, -1, 0);
	for(int i = 0; i < e[x].size(); ++ i){
		int u = e[x][i];
		if(!visit[u]){
			solve(u);
		}
	}
}
int main(void)
{
	int n, x, y, w;
	scanf("%d",&n);
	for(int i = 1; i < n; ++ i){
		cin >> x >> y >> w;
		e[x].PB(MP(y, w));
		e[y].PB(MP(x, w));
	}
	ans = 0;
	solve(1);
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:24:9: error: reference to 'size' is ambiguous
   24 |         size[x] = 1;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc:29:20: error: too few arguments to function 'void dfs(int, int)'
   29 |                 dfs(u);
      |                 ~~~^~~
a.cc:22:6: note: declared here
   22 | void dfs(int x, int fa)
      |      ^~~
a.cc:30:17: error: reference to 'size' is ambiguous
   30 |                 size[x] += size[u];
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc:30:28: error: reference to 'size' is ambiguous
   30 |                 size[x] += size[u];
      |                            ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc:31:46: error: reference to 'size' is ambiguous
   31 |                 balence[x] = max(balence[x], size[u]);
      |                                              ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc: In function 'int GetRoot(int)':
a.cc:40:21: error: reference to 'size' is ambiguous
   40 |         int total = size[x];
      |                     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc:42:46: error: reference to 'size' is ambiguous
   42 |         int val = max(balence[root], total - size[root]);
      |                                              ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc:45:51: error: reference to 'size' is ambiguous
   45 |                 int tmp = max(balence[u], total - size[u]);
      |                                                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:21:27: note:                 'int size [100010]'
   21 | int balence[N], visit[N], size[N];
      |                           ^~~~
a.cc: In function 'void dfs2(int, int, int)':
a.cc:60:1: error: a function-definition is not allowed here before '{' token
   60 | {
      | ^
a.cc:72:1: error: a function-definition is not allowed here before '{' token
   72 | {
      | ^
a.cc:84:2: error: expected '}' at end of input
   84 | }
      |  ^
a.cc:56:1: note: to match this '{'
   56 | {
      | ^