Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn = 300001;
int val[maxn], n, ans = 2147483647;
int cnt[maxn], dis[maxn], dec[maxn];
vector < int > edge[maxn];
struct cmp{
	bool operator()(const int &a, const int &b)const{
		return dis[a] < dis[b];
	}
};
void cal(int now, int last = 0){
	cnt[now] = dis[now] = dec[now] = 0;
	int ll = 0;
	for(auto &i : edge[now]){
		if(i != last){
			cal(i, now);
			dec += min(ll, dis[i]);
			if(ll > dis[i]){
				ll -= dis[i];
			}
			else ll = 0;
			dis[now] += dis[i] + cnt[i];
			cnt[now] += cnt[i];
		}
	}
	if(now == root and dec == dis[now]){
		ans = min(ans, dec[now]);
	}
	cnt[now] += val[now];
}	
int main(){	
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	string s;
	cin >> s;
	for(int i = 1;i <= n;++i)val[i] = s[i - 1] == '1';
	for(int a, b, i = 1;i < n;++i){
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	for(int i = 1;i <= n;++i)cal(i);
	if(ans == 2147483647)cout << -1 << '\n';
	else cout << ans << '\n';
}


Compiler output:
a.cc: In function 'void cal(int, int)':
a.cc:13:31: error: reference to 'dec' is ambiguous
   13 |         cnt[now] = dis[now] = dec[now] = 0;
      |                               ^~~
In file included from /usr/include/c++/14/streambuf:43,
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54,
                 from a.cc:1:
/usr/include/c++/14/bits/ios_base.h:1079:3: note: candidates are: 'std::ios_base& std::dec(ios_base&)'
 1079 |   dec(ios_base& __base)
      |   ^~~
a.cc:5:27: note:                 'int dec [300001]'
    5 | int cnt[maxn], dis[maxn], dec[maxn];
      |                           ^~~
a.cc:18:25: error: reference to 'dec' is ambiguous
   18 |                         dec += min(ll, dis[i]);
      |                         ^~~
/usr/include/c++/14/bits/ios_base.h:1079:3: note: candidates are: 'std::ios_base& std::dec(ios_base&)'
 1079 |   dec(ios_base& __base)
      |   ^~~
a.cc:5:27: note:                 'int dec [300001]'
    5 | int cnt[maxn], dis[maxn], dec[maxn];
      |                           ^~~
a.cc:27:19: error: 'root' was not declared in this scope
   27 |         if(now == root and dec == dis[now]){
      |                   ^~~~
a.cc:27:28: error: reference to 'dec' is ambiguous
   27 |         if(now == root and dec == dis[now]){
      |                            ^~~
/usr/include/c++/14/bits/ios_base.h:1079:3: note: candidates are: 'std::ios_base& std::dec(ios_base&)'
 1079 |   dec(ios_base& __base)
      |   ^~~
a.cc:5:27: note:                 'int dec [300001]'
    5 | int cnt[maxn], dis[maxn], dec[maxn];
      |                           ^~~
a.cc:28:32: error: reference to 'dec' is ambiguous
   28 |                 ans = min(ans, dec[now]);
      |                                ^~~
/usr/include/c++/14/bits/ios_base.h:1079:3: note: candidates are: 'std::ios_base& std::dec(ios_base&)'
 1079 |   dec(ios_base& __base)
      |   ^~~
a.cc:5:27: note:                 'int dec [300001]'
    5 | int cnt[maxn], dis[maxn], dec[maxn];
      |                           ^~~