criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<iostream>
using namespace std;
int main(){
  int N,X;
  cin >> N >> X;
  int b[N];
  int min[N];
  int max[N];
  int sum = 0;
  for(int i = 0;i < N;i++){
    cin >> b[i] >> min[i] >> max[i];
    sum += min[i] * b[i];
  }
  int num=0;
  int keep=0;
  while(1){
    for(int i=0;i<N;i++){
      if(keep < max[i]){
        num = i;
        keep = max[i];
      }
    }
    if(sum < sum - max[num] * X + b[num] * (max[num] -  min[num])){
      count += (sum + b[num] * (max[num] -  min[num])) / max[num]  + 1;
      break;
    }else{
      sum = sum - max[num] * X + b[num] * (max[num] -  min[num]);
      max[i] =0;
      count += X;
    }
  }
}



Compiler output:
a.cc: In function 'int main()':
a.cc:24:7: error: 'count' was not declared in this scope
   24 |       count += (sum + b[num] * (max[num] -  min[num])) / max[num]  + 1;
      |       ^~~~~
a.cc:28:11: error: 'i' was not declared in this scope
   28 |       max[i] =0;
      |           ^
a.cc:29:7: error: 'count' was not declared in this scope
   29 |       count += X;
      |       ^~~~~
Language: C++

#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, X;
    cin >> N >> X;

    struct Test {
        ll b, l, r;
    };
    vector<Test> tests(N);
    for (ll i = 0; i < N; i++) {
        cin >> tests[i].b >> tests[i].l >> tests[i].r;
    }
    sort(tests.begin(), tests.end(), [&](Test& lhs, Test& rhs) {
        return (X - lhs.b) * lhs.r + lhs.b * lhs.l >= (X - rhs.b) * rhs.r + rhs.b * rhs.l;
    });

    struct Element {
        ll type, add, num, index;
        bool operator<(const Element& rhs) const {
            return add < rhs.add;
        }
    };

    ll ok = X * N, ng = -1;
    while (ok != ng + 1) {
        ll mid = (ok + ng) / 2;
        
        ll a = mid / X;
        ll b = mid % X;

        //ll sum = 0;
        priority_queue<Element> pq;

        //for (ll i = 0; i < N; i++) {
        //    if (i < a) {
        //        sum += (X - tests[i].b) * tests[i].r;
        //    } else {
        //        sum -= tests[i].b * tests[i].l;
        //        pq.push({ 0, tests[i].l, tests[i].b, i });
        //    }
        //}

        //while (sum < 0 && b > 0 && !pq.empty()) {
        //    auto t = pq.top();
        //    pq.pop();

        //    ll op_num = min(t.num, b);
        //    ll max_add = t.add * op_num;
        //    sum += max_add;
        //    b -= op_num;
        //    if (t.type == 0) {
        //        pq.push({ 1, tests[t.index].r, X - tests[t.index].b, t.index });
        //    }
        //}

        (sum >= 0 ? ok = mid : ng = mid);
    }

    cout << ok << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:10: error: 'sum' was not declared in this scope
   59 |         (sum >= 0 ? ok = mid : ng = mid);
      |          ^~~
Language: C++

#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
#define double long double
#define go {cout<<"Yes"<<endl;return 0;}
#define fin {cout<<"No"<<endl;return 0;}
//template

//main
signed main(){
  int o=0;
  int N,X;cin>>N>>X;
  std::vector<int> b(N),l(N),h(N);
  for(int i=0;i<N;i++)cin>>b[i]>>l[i]>>h[i];
  int ans=N*X;int res=0;
  for(int i=0;i<N;i++)res+=h[i]*(X-b[i]);
  typedef pair<double,int> P;
  std::vector<P> v(N);
  for(int i=0;i<N;i++)v[i]=P((float)(b[i]+(X-b[i]))/(b[i]*l[i]+h[i]*(X-b[i])),i);//cout<<v[i].first<<endl;}
  sort(v.rbegin(),v.rend());
  std::vector<int> used(N,1);
  for(int j=0;j<N;j++){
    if(res==0)break;
    int i=v[j].second;
    //cout<<i<<" "<<res<<" "<<h[i]*(X-b[i])+l[i]*b[i]<<endl;
    if(res>=h[i]*(X-b[i])+l[i]*b[i]){
      res-=h[i]*(X-b[i])+l[i]*b[i];
      ans-=X;used[i]=1;
      continue;
    }
    int a=res-h[i]*(X-b[i])-l[i]*b[i];
    a*=-1;
    a--;a/=l[i];int t=a+1;
    if(t>b[i]){used[i]=0;continue;}
    res-=h[i]*(X-b[i])+l[i]*(b[i]-t);
    ans-=(X-t);
  }
  //cout<<111<<" "<<ans<<endl;
  std::vector<int> va;
  for(int i=0;i<N;i++)if(used[i]==0)va.push_back(h[i]);
  //cout<<222<<" "<<va.size()<<endl;
  sort(va.begin(),va.end());
  for(int p:va){
    int t=res/p;
    if(t>b[i]){t/=o;}
    res-=t*p;ans-=t;
  }
  cout<<ans<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:12: error: 'i' was not declared in this scope
   47 |     if(t>b[i]){t/=o;}
      |            ^
Language: C++

#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
LL X;

struct Data {
    LL b, l, u;
    LL d;

    bool operator<(const Data &o) const {
	return d > o.d;
    }
} D[100011];

bool ok(LL mid) {
    if (mid >= X*N) return true;

    LL p = mid / X;
    if (p >= N) return true;
    LL rest = mid % X;

    LL sum = 0;
    REP (i, p) sum += D[i].u * (X - D[i].b);

    LL tmp = 0;
    for (int i=p; i<N; i++) {
	sum -= D[i].l * D[i].b;
	if (rest <= D[i].b) amax(tmp, D[i].l * rest);
	else amax(tmp, (D[i].l-D[i].u)*D[i].b + D[i].u*rest);
    }

    if (sum + tmp >= 0) return true;
    if (p == 0) return false;

    sum += D[p].u * (X-D[i].b);
    sum -= D[p].l * D[p].b;
    REP (i, p) {
	LL g = sum - D[i].u * (X - D[i].b);
	if (rest <= D[i].b) g += D[i].l * (rest - D[i].b);
	else g += D[i].u * (rest - D[i].b);
	if (g >= 0) return true;
    }
    return false;
}

void MAIN() {
    scanf("%d%lld", &N, &X);
    LL sum = 0;
    REP (i, N) {
	LL b, l, u;
	scanf("%lld%lld%lld", &b, &l, &u);
	D[i].b = b;
	D[i].l = l;
	D[i].u = u;
	D[i].d = u*(X-b)+l*b;
	sum += u*(X-b);
    }

    sort(D, D+N);
    LL lo = -1, hi = N*X;
    while (hi - lo > 1) {
	LL mid = (lo + hi) / 2;
	(ok(mid)? hi: lo) = mid;
    }

    printf("%lld\n", hi);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Compiler output:
a.cc: In function 'bool ok(LL)':
a.cc:63:26: error: 'i' was not declared in this scope
   63 |     sum += D[p].u * (X-D[i].b);
      |                          ^
Language: C

#include <stdio.h>
#include<stdlib.h>
void quicksort(int a[], int left, int right)
{
	int p;	
	int L = left, R = right;		
	int temp;
	p = a[(left + right) / 2];
	while (1)
	{
		while (a[L] < p) L++; while (a[R] > p)
			R--;
		
		if (L >= R)
			break;

		temp = a[R];
		a[R] = a[L];
		a[L] = temp;

		L++;
		R--;
	}


int main(void){
	int n,x,b[100000],l[100000],u[100000],i,a=0,c=0;
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++){
      scanf("%d %d %d",&b[i],&l[i],&u[i]);
      a+=b[i]*l[i];
    }
    quicksort(l,0,n-1);
    for(i=n-1;i>=0;i--){
      if(a/l[i]>x){
        a=a-x*l[i];
        c+=x;
      }
      else {
        if(a%l[i]!=0)c+=(a/l[i]+1);
        else c+=a/l[i];
        break;
      }
    }
  printf("%d",c);
  return 0;
}

Compiler output:
main.c: In function 'quicksort':
main.c:47:1: error: expected declaration or statement at end of input
   47 | }
      | ^
Language: C++

10 1000
451 4593 6263
324 310 6991
378 1431 7068
71 1757 9218
204 3676 4328
840 6221 9080
684 1545 8511
709 5467 8674
862 6504 9835
283 4965 9980

Compiler output:
a.cc:1:1: error: expected unqualified-id before numeric constant
    1 | 10 1000
      | ^~
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:18:30: error: incompatible types in assignment of 'int' to 'int [300001]'
   18 |                         _dec += min(ll, dis[i]);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~
a.cc:27:19: error: 'root' was not declared in this scope
   27 |         if(now == root and _dec == dis[now]){
      |                   ^~~~
a.cc:27:33: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   27 |         if(now == root and _dec == dis[now]){
      |                            ~~~~~^~~~~~~~~~~
Language: C

#include <bits/stdc++.h>
#define il inline
const int N=2005;

int n,ans=1e9,s[N],f[N],dis[N],sz[N];
int to[N+N],nx[N+N],hd[N],sze;

il void add(int u,int v){to[++sze]=v,nx[sze]=hd[u],hd[u]=sze;}

il void dfs(int u,int F)
{
	sz[u]=s[u]; int i,v,mx=0;
	for (i=hd[u]; i; i=nx[i]) if ((v=to[i])!=F)
	{
		dfs(v,u),sz[u]+=sz[v],dis[u]+=dis[v]+=sz[v];
		if (dis[mx]<=dis[v]) mx=v;
	}
	if (!mx) return;
	if (dis[u]>=2*dis[mx]) f[u]=dis[u]/2;
    else f[u]=dis[u]-dis[mx]+std::min(f[mx],(2*dis[mx]-dis[u])/2);
}

int main()
{
	scanf("%d\n",&n); int i,j,u,v;
	for (i=1; i<=n; i++) s[i]=getchar()^48;
	for (i=1; i<n; i++) scanf("%d%d",&u,&v),add(u,v),add(v,u);
	
	for (i=1; i<=n; i++)
	{
        memset(dis,0,4*n+4),memset(sz,0,4*n+4),memset(f,0,4*n+4),dfs(i,0);
		if (dis[i]&1^1) (2*f[i]>=dis[i])&&(ans=std::min(ans,dis[i]/2));
	}
	if (ans==1e9) puts("-1");
	else printf("%d",ans);
	
	return 0;
}

Compiler output:
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory
    1 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include <bits/stdc++.h>

using namespace std;

const int inf = 1000000000;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	string s;
	cin >> s;

	vector<vector<int> > G(n);
	for(int i = 0; i < n - 1; ++i) {
		int x, y;
		cin >> x >> y;
		--x; --y;
		G[x].emplace_back(y);
		G[y].emplace_back(x);
	}

	vector<int> dep(n);
	vector<int> dp(n);
	vector<int> sz(n);
	vector<int> Sum(n);

	function<void(int, int)> dfs = [&] (int u, int f) {
		sz[u] = (s[u] == '1');
		dp[u] = 0;
		Sum[u] = dep[u] * (s[u] == '1');
		for(int v : G[u]) {
			if(v != f) {
				dep[v] = dep[u] + 1;
				dfs(v, u);
				dp[u] = max(dp[u], dp[v] + sz[v]);
				sz[u] += sz[v];
				Sum[u] += Sum[v];
			}
		}
	};

	int ans = inf;
	for(int i = 0; i < n; ++i) {
		dep[i] = 0;	
		dfs(i, -1);

		int tmp = 0;
		bool ok = true;

		for(int j : G[i]) {
			tmp += dp[j];
		}

		for(int j : G[i]) {
			if(dp[j] > Sum[i] - Sum[j]) {
				ok = false;
			}
		}

		if(ok && sum % 2 == 0) {
			ans = min(ans, sum / 2);
		}
	}

	if(ans == inf) {
		cout << -1 << '\n';
	} else {
		cout << ans << '\n';
	}

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:64:26: error: 'sum' was not declared in this scope; did you mean 'Sum'?
   64 |                 if(ok && sum % 2 == 0) {
      |                          ^~~
      |                          Sum
Language: C++

#include<cstdio>
#define INF 2e9
#define N 100010
using namespace std;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f; 
}
int n,m;
bool a[N];
struct Edge{
	int v,nxt;
}e[N<<1];
int head[N],size;
void add(int u,int v)
{
	e[++size].v=v;
	e[size].nxt=head[u];
	head[u]=size;
}
int dep[N],f[N],sum[N],pct[N];
void dfs(int u,int fa)
{
	dep[u]=dep[fa]+1;
	int pos=0;
	sum[u]=0;
	pct[u]=a[u];
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==fa)continue;
		dfs(v,u);
		sum[u]=sum[u]+sum[v]+pct[v];
		pct[u]+=pct[v];
		if(sum[v]+pct[v]>sum[pos]+pct[pos])pos=v;
	}
	if(2*(sum[pos]+pct[pos])<=sum[u])f[u]=sum[u]/2;
	else f[u]=sum[u]-sum[pos]-pct[pos]+min(f[pos],(2*(sum[pos]+pct[pos])-sum[u])/2);
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)scanf("%1d",&a[i]);
	for(int i=1;i<n;++i)
	{
		int x=read(),y=read();
		add(x,y);
		add(y,x);
	}
	dep[0]=-1;
	int ans=INF;
	for(int i=1;i<=n;++i)
	{
		dfs(i,0);
		if(2*f[i]==(sum[i]-a[i]))ans=min(ans,f[i]); 
	}
	if(ans==INF)ans=-1;
	printf("%d",ans);
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:41:44: error: 'min' was not declared in this scope
   41 |         else f[u]=sum[u]-sum[pos]-pct[pos]+min(f[pos],(2*(sum[pos]+pct[pos])-sum[u])/2);
      |                                            ^~~
a.cc: In function 'int main()':
a.cc:58:46: error: 'min' was not declared in this scope; did you mean 'main'?
   58 |                 if(2*f[i]==(sum[i]-a[i]))ans=min(ans,f[i]);
      |                                              ^~~
      |                                              main
Language: C++

#include<bits/stdc++.h>
#define maxn 2010
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int a[maxn];
char s[maxn];
int head[maxn],nxt[maxn*2],to[maxn*2],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
ll mn[maxn],mx[maxn];
int g[maxn];
int solve(int x,int las)
{
    mx[x]=mn[x]=0;g[x]=a[x];
    int p=0;
    for(int i=head[x];i;i=nxt[i])
    {
        if(to[i]==las)  continue;
        solve(to[i],x);
        g[x]+=g[to[i]];
        mx[x]+=mx[to[i]];
        if(mx[to[i]]>mx[p])  p=to[i];
    }
    if(mn[p]>mx[x]-mx[p])  mn[x]=mn[p]+mx[p]-mx[x]+g[x];
    else                   mn[x]=(mx[x]&1)+g[x];
    mx[x]+=g[x];
    if(!las)  mn[x]-=g[x],mx[x]-=g[x];
}
ll ans=inf;
int main()
{
    n=read();
    scanf("%s",s+1);for(int i=1;i<=n;i++)  a[i]=s[i]-'0';
    for(int i=1;i<n;i++)
    {
        int q=read(),w=read();
        add(q,w);add(w,q);
    }
    for(int i=1;i<=n;i++)
    {
        solve(i,0);
        if(!mn[i])  ans=min(ans,mx[i]/2);
    }
    if(ans==inf)  puts("-1");
    else          cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int solve(int, int)':
a.cc:42:1: warning: no return statement in function returning non-void [-Wreturn-type]
   42 | }
      | ^
a.cc: At global scope:
a.cc:43:8: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   43 | ll ans=inf;
      |        ^~~
      |        ynf
a.cc: In function 'int main()':
a.cc:58:13: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   58 |     if(ans==inf)  puts("-1");
      |             ^~~
      |             ynf
Language: C++

#include <bits/stdc++.h>

#define mp make_pair
#define X first
#define Y second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FOD(i, a, b) for(int i = a; i >= b; i--)

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;

const int N = 2010;
const int INF = 1e9 + 7;

int n, low[N], high[N], cnt[N];
bool hasPices[N];
vector <int> adj[N];

void dfs(int u, int p){
    cnt[u] = hasPices[u];
    high[u] = 0;
    int maxLow = 0;
    for(int v : adj[u])
        if (v != p){
            dfs(v, u);
            cnt[u] += cnt[v];
            high[u] += high[v] + cnt[v];
            maxLow = max(maxLow, low[v] + cnt[v]);
        }
    if (Q.empty()){
        low[u] = 0;
    } else {
        int x = maxLow;
        int sum = 0;
        for(int v : adj[u])
            if (v != p)
                sum += min(high[v] + cnt[v], x - abs(high[v] + cnt[v] - x) % 2);
        if (x * 2 > sum)
            low[u] = x * 2 - sum;
        else
            low[u] = sum % 2;
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    string s;
    cin >> s;
    FOR(i, 1, n)
        hasPices[i] = (s[i - 1] == '1');
    FOR(i, 1, n - 1){
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int ans = INF;
    FOR(i, 1, n){
        dfs(i, i);
        if (low[i] == 0)
            ans = min(ans, high[i] / 2);
    }
    cout << (ans == INF? -1 : ans);

    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:32:9: error: 'Q' was not declared in this scope
   32 |     if (Q.empty()){
      |         ^
Language: C++

/*
* @Author: wxyww
* @Date: 2020-03-09 19:23:54
* @Last Modified time: 2020-03-09 19:43:36
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstring>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int N = 2010,INF = 1e9;
ll read() {
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
char s[N];
int mn[N],mx[N],siz[N];
struct node {
	int v,nxt;
}e[N << 1];
int head[N],ejs;
void add(int u,int v) {
	e[++ejs].v = v;e[ejs].nxt = head[u];head[u] = ejs;
}

void dfs(int u,int fa) {
	siz[u] = s[u] - '0';
	int x = 0;
	for(int i = head[u];i;i = e[i].nxt) {
		int v = e[i].v;
		if(v == fa) continue;

		dfs(v,u);

		if(mx[v] + siz[v] > mx[x] + siz[x]) x = v;
		mx[u] += mx[v] + siz[v];
		siz[u] += siz[v];
	}
	
	if(2 * (mn[x] + siz[x])> mx[u]) {
		mn[u] = ((mx[x] + siz[x]) + (mn[x] + siz[x]) - (mx[u] - (mx[x] + siz[x])));
	} 
	else mn[u] = mx[u] & 1;
}

int main() {
	int n = read();
	scanf("%s",s + 1);
	for(int i = 1;i <= n;++i) s[i] - '0';

	for(int i = 1;i < n;++i) {
		int u = read(),v = read();
		add(u,v);add(v,u);
	}
	int ans = INF; 
	for(int i = 1;i <= n;++i) {
		memset(mx,0,sizeof(mx));
		memset(mn,0,sizeof(mn));q
		dfs(i,0);
		if(!mn[i]) {
			ans = min(ans,mx[i] >> 1);
		}
	}
	if(ans == INF) puts("-1");
	else cout<<ans<<endl; 
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:75:41: error: 'q' was not declared in this scope
   75 |                 memset(mn,0,sizeof(mn));q
      |                                         ^
Language: C++

#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int N=2005;
int n,sz[N],dp[N],ans=1<<30;
char str[N];vector<int>E[N];
void dfs(int u,int f){
	sz[u]=str[u]-'0';dp[u]=0;
	for(int v:E[u])
		if(v!=f){
			dfs(v,u);sz[u]+=sz[v];
			dp[u]+=dp[v]+sz[v];
		}
}
int calc(int u,int f){
	int son=0;
	for(int v:E[u])
		if(v!=f&&dp[v]+sz[v]>dp[son]+sz[son])
			son=v;
	if(!son)return 0;
	int val=calc(son,u)+sz[son];
	if(dp[u]-dp[son]-sz[son]>=k)
		return dp[u]&1;
	else
		return val-(dp[u]-dp[son]-sz[son]);
}
int main(){
	scanf("%d%s",&n,str+1);
	for(int i=1,x,y;i<n;++i){
		scanf("%d%d",&x,&y);
		E[x].push_back(y);E[y].push_back(x);
	}
	for(int i=1;i<=n;++i){
		dfs(i,0);
		if(!calc(i,0))ans=min(ans,dp[i]>>1);
	}
	printf("%d\n",ans==1<<30?-1:ans);
	return 0;
}


Compiler output:
a.cc: In function 'int calc(int, int)':
a.cc:23:35: error: 'k' was not declared in this scope
   23 |         if(dp[u]-dp[son]-sz[son]>=k)
      |                                   ^
a.cc:22:35: warning: control reaches end of non-void function [-Wreturn-type]
   22 |         int val=calc(son,u)+sz[son];
      |                                   ^
Language: C++

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
string s;
int n;
vector<int> vertexs[3000];
long long dfs(long long now, long long back, long long itr) {
	long long ans = 0;
	if (s[now] == '1') ans += itr;
	REP(i, vertexs[now].size()) {
		int going = vertexs[now][i];
		if (going == back) continue;
		ans += dfs(going, now, itr + 1);
	}
	return ans;
}
int main() {
	iostream::sync_with_stdio(false);
	cin.tie(false);
	cin >> n;
	cin >> s;
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		vertexs[a].push_back(b);
		vertexs[b].push_back(a);
	}
	long long ans = LONG_INF;
	for (int i = 0; i < n; ++i) {
		long long geko = dfs(i, -1, 0);
		if (geko % 2 == 0) {
			ans = min(ans, geko / 2);
		}
	}
	if (ans == LONG_INF) ans = -1;
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:58:16: error: no matching function for call to 'std::basic_istream<char>::tie(bool)'
   58 |         cin.tie(false);
      |         ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/ios:46,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:15:
/usr/include/c++/14/bits/basic_ios.h:299:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]'
  299 |       tie() const
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:299:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/14/bits/basic_ios.h:311:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |       ^~~
/usr/include/c++/14/bits/basic_ios.h:311:43: note:   no known conversion for argument 1 from 'bool' to 'std::basic_ostream<char>*'
  311 |       tie(basic_ostream<_CharT, _Traits>* __tiestr)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
Language: C++

#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<class T1, class T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template<class T1, class T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define push_back push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);
const int MAXN = 2029;


int n;
string s;
vector<int> g[3005];
int dist[3005];
int cnt = 0;


void dfs(int u, int pr)
{
	for(int i=0;i<g[u].size();i++)
	{
		int h=g[u][i];
		if(pr==h)
		{
			continue;
		}
		dist[h]=dist[u]+1;
		dfs(h,u);
	}
	if(s[u]=='1')
	{
		cnt+=dist[u];
	}
}
int cnts[3005];
int dfs1(int u,int pr)
{
	cnts[u]=0;
	if(s[u]=='1')
	{
		cnts[u]++;
	}
	int cur=0;
	vector<pair<int,int> >st;
	for(int i=0;i<g[u].size();i++)
	{
		int h=g[u][i];
		if(pr==h)
		{
			continue;
		}
		int tmp=dfs1(h,u);
		st.push_back({tmp,h});
		cnts[u]+=cnts[h];
		cur+=tmp;
	}
	if(st.empty())
	{
		if(s[u]=='1')
		{
			return dist[u];
		}
		return 0;
	}
	int ans=0;
	if(s[u]=='1')
	{
		ans+=dist[u];
	}
	for(auto &x: st)
	{
		ans+=dist[u]*cnts[x.second];
		x.first-=dist[u]*cnts[x.second];
		cur-=dist[u]*cnts[x.second];
	}
	sort(all(st));
	if(st.back().first<=cur-st.back().first)
	{
		ans+=cur%2;
	}
	else
	{
		int tmp=2*st.back().first;
		for(auto x: st)
		{
			tmp-=x.first;
		}
		ans+=tmp;
	}
	return ans;
}
int main()
{
	cin>>n;
	cin>>s;
	for (int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int res=INF;
	for(int i=0;i<n;i++)
	{
		int sum=0;
		int tmp=0;
		int pos=-1;
		for(int j=0;j<g[i].size();j++)
		{
			int h=g[i][j];
			cnt=0;
			dist[h]=1;
			dfs(h,i);
			tmp=max(tmp,cnt);
			if(tmp==cnt)
			{
				pos=h;
			}
			sum+=cnt;
		}
		if(sum%2==0 and tmp<=sum/2)
		{
			res=min(res,sum/2);
		}
		else
		{
			if(sum%2==0)
			{
				if(res>sum/2)
				{
					int f=dfs1(pos,i);
					int ft=sum-tmp;
					if(f<=ft)
					{
						res=min(res,sum/2);
					}
				}
			}
		}
	}
	if(res>=INF)
	{
		res=-1;
	}
	cout<<res;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:129:17: error: 'INF' was not declared in this scope
  129 |         int res=INF;
      |                 ^~~
Language: C++

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

const long long INF = 1e9;

vector<vector<int>> graph;
string val;

pair<int, int> _dfs(int u, int p)
{
    pair<int, int> ret = {0, val[u] == '1'};
    
    for (int v: graph[u])
    {
        if (v == p)
            continue;
        
        pair<int, int> tmp = _dfs(v, u);
        ret.first += tmp.first + tmp.second;
        ret.second += tmp.second;
    }
    
    return ret;
}

int dp[10000000];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n >> val;
    graph.resize(n);
    for (int i = 1; i != n; ++i)
    {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    
    int ans = INF;
    int u = -1;
    for (int i = 0; i != n; ++i)
    {
        int tmp = _dfs(i).first;
        if (tmp < ans)
        {
            ans = tmp;
            u = i;
        }
    }
    
    if (ans & 1)
        cout << -1 << '\n';
    else
    {
        vector<int> kek;
        for (int v: graph[u])
            if (_dfs(v).first * 2 > ans)
            {
                cout << -1 << '\n';
                return 0;
            }
        
        cout << ans / 2 << '\n';
    }
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:23: error: too few arguments to function 'std::pair<int, int> _dfs(int, int)'
   50 |         int tmp = _dfs(i).first;
      |                   ~~~~^~~
a.cc:9:16: note: declared here
    9 | pair<int, int> _dfs(int u, int p)
      |                ^~~~
a.cc:64:21: error: too few arguments to function 'std::pair<int, int> _dfs(int, int)'
   64 |             if (_dfs(v).first * 2 > ans)
      |                 ~~~~^~~
a.cc:9:16: note: declared here
    9 | pair<int, int> _dfs(int u, int p)
      |                ^~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
vector<int> E[2020];
vector<int> Ds[2020];
int SD[2020];
int D[2020][2020];
int lef;

void dfs(int cur,int pre,int id,int d) {
	if(S[cur]=='1') {
		Ds[id].push_back(d);
		SD[id]+=d;
	}
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur,id,d+1);
	
}

void dfs1(int cur,int pre,int id,int d) {
	D[cur][id]=d;
	FORR(e,E[cur]) if(e!=pre) dfs1(e,cur,id,d+1);
}

pair<int,int> can(int cur,int pre) {
	pair<int,int> P={0,0};
	
	if(S[cur]=='1') P.first=1;
	FORR(e,E[cur]) if(e!=pre) {
		auto Q=can(e,cur);
		Q.second+=Q.first;
		mi=min(Q.second,P.second);
		lef-=mi;
		Q.second-=mi;
		P.second-=mi;
		P.first+=Q.first;
		P.second+=Q.second;
	}
	return P;
	
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cin>>S;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	FOR(x,N) dfs1(x,x,x,0);
	
	int mi=1<<30;
	FOR(x,N) {
		ZERO(SD);
		FOR(y,N) Ds[y].clear();
		FORR(e,E[x]) dfs(e,x,e,1);
		int sum=0;
		int num=0;
		FOR(y,N) {
			sum+=SD[y];
			if(SD[y]>0) num++;
		}
		
		if(sum%2) continue;
		int ma=*max_element(SD,SD+N);
		if(ma*2<=sum) {
			mi=min(mi,sum/2);
			continue;
		}
		y=max_element(SD,SD+N)-SD;
		lef=(ma-(sum-ma))/2;
		can(y,x);
		if(lef<=0) mi=min(mi,sum/2);
	}
	if(mi==1<<30) mi=-1;
	assert(mi!=-1);
	cout<<mi<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Compiler output:
a.cc: In function 'std::pair<int, int> can(int, int)':
a.cc:44:17: error: 'mi' was not declared in this scope
   44 |                 mi=min(Q.second,P.second);
      |                 ^~
Language: C++

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define IN freopen("transposition-115.txt","r",stdin)
#define OUT freopen("dichromatic.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 2000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define SZ(v) ((int)v.size())
#define sq(x)  ((x)*(x))

using namespace __gnu_pbds;
using namespace std ;

#define maxn 2005
#define mod 1000000007LL

typedef pair<i64,i64> pii ;
typedef  long long int T ;

char s[maxn] ;
int cnt[maxn] , sum[maxn] , mnSum[maxn] ;
vector <int> g[maxn] ;

void dfs(int u, int par)
{
    cnt[u] = s[u] ;
    int mnsum = 0 , mx = 0 ;
    for(auto v:g[u])
    {
        if(v==par) continue ;
        dfs(v,u) ;
        sum[u] += (sum[v] +cnt[v]) ;
        cnt[u] += cnt[v] ;
        mnsum += (mnSum[v]+cnt[v]) ;
        mx = max(mx,mnSum[v]+cnt[v]) ;
    }

    int op = min( mx , mnsum/2 ) ;
    mnSum[u] = mnsum - op*2 ;

 //   printf("%d: %d %d\n",u,sum[u],cnt[u]) ;
    return ;
}

int main()
{
    int n ;
    scanf("%d",&n) ;
    scanf("%s",s+1) ;

    for(int i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }
    for(int i=1 ; i<=n ; i++) s[i] -= '0' ;

    int ans = INF ;

    for(int root= 1 ; root<=1; root++)
    {
        vector <int> res ;
        memset(sum,0,sizeof(sum)) ;
        memset(cnt,0,sizeof(cnt)) ;

        int sm = 0 , mx = 0 , id=0 ;

        for(int i=0 ; i<g[root].size() ; i++)
        {
            int v = g[root][i] ;
            dfs( v ,root ) ;
            res.pb( sum[v] + cnt[v] ) ;
            sm += sum[v] + cnt[v] ;
            if( sum[v] + cnt[v] > mx )
            {
                mx = sum[v] + cnt[v] ;
                id = v ;
            }
            else if( sum[v] + cnt[v] == mx && mx !=0 && mnSum[v]+cnt[v] < mnSum[id]+cnt[id] ) id = v ;
        }

//        printf("root:%d %d %d\n",root,sm,)

        if( sm%2==0 && (mnSum[id]+cnt[id])*2 <= sm-mx+mnSum[id]+cnt[id]) )
        {
            ans = min(ans,sm/2) ;
        }
    }

    if( ans==INF ) printf("-1\n") ;
    else printf("%d\n",ans) ;

    return 0 ;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:96:74: error: expected primary-expression before ')' token
   96 |         if( sm%2==0 && (mnSum[id]+cnt[id])*2 <= sm-mx+mnSum[id]+cnt[id]) )
      |                                                                          ^
Language: C++

#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:


vector<int> graph[2010];
int depth[2010];

void dfs(int v,int p,int d){
	depth[v] = d;
	for(auto &v2:grpah[v]){
		if(v2 == p) continue;
		dfs(v2, v, d + 1);
	}
}

int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;

	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		graph[a-1].push_back(b-1);
		graph[b-1].push_back(a-1);
	}


	const int inf = 1 << 20;
	int ans = inf;

	rep(i, n){
		dfs(i, -1, 0);
		int total = 0;
		rep(j, n) if(s[j] == '1') total += depth[j];
		if(total % 2 == 0) chmin(ans, total / 2);
	}

	if(ans == inf) 
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:67:22: error: 'grpah' was not declared in this scope; did you mean 'graph'?
   67 |         for(auto &v2:grpah[v]){
      |                      ^~~~~
      |                      graph
Language: C++

#include<iostream>
#include<vector>
#include<string>

using namespace std;

typedef struct node_T
{
        vector<node_T*> neighbor;
        long koma;
}node;

long search(node* n, node* prev, long len);

long main(){
        long n;
        cin >> n;
        node* tree = new node[n];

        string str;
        cin >> str;
        for(long i=0;i<n;i++){
                tree[i].koma = str[i] == '0' ? 0 : 1;
        }

        for(long i=0;i<n-1;i++){
                long a,b;
                cin >> a >> b;
                a-=1;
                b-=1;
                tree[a].neighbor.push_back(&tree[b]);
                tree[b].neighbor.push_back(&tree[a]);
        }

        long ans = -1;
        for(long i=0;i<n;i++){
                long sum = 0;
                long max = 0;
                for(auto nx : tree[i].neighbor){
                        long ret = search(nx, &tree[i], 1);
                        sum += ret;
                        if(max < ret){
                                max = ret;
                        }
                }

                if(sum % 2 == 0 && 2 * max <= sum){
                        //cout << "c:" << i+1 << " sum:" << sum << endl;
                        if(ans == -1 || sum/2 < ans){
                                ans = sum / 2;
                        }
                }
        }

        cout << ans << endl;
}

long search(node* n, node* prev, long len)
{
        long score = len * n->koma;
        for(auto nx : n->neighbor){
                if(nx != prev){
                        score += search(nx, n, len + 1);
                }
        }
        return score;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

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


const int N=2000;

vector<int> es[N];
inline void ae(int u,int v){
	es[u].push_back(v);
}
#define Fs(x) for(vector<int>::iterator it=es[x].begin();it!=es[x].end();++it)

LL dfs(int x,int fa=-1,int c=1,int dep=0){
	LL ans=dep;
	Fs(x){
		if(*it==fa)continue;
		ans+=dfs(*it,x,-c,dep+1);
	};
}

char s[N];
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;i<n-1;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		ae(u,v);
		ae(v,u);
	}
	LL ans=LONG_LONG_MAX;
	for(int i=1;i<=n;i++){
		LL a=dfs(i);
	if(a&1==0)ans=min(ans,a/2);
	
	}
	cout<<(a==LONG_LONG_MAX?-1:a)<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'LL dfs(int, int, int, int)':
a.cc:20:1: warning: no return statement in function returning non-void [-Wreturn-type]
   20 | }
      | ^
a.cc: In function 'int main()':
a.cc:39:16: error: 'a' was not declared in this scope
   39 |         cout<<(a==LONG_LONG_MAX?-1:a)<<endl;
      |                ^
Language: C++

#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:


vector<int> grpah[2010];
int depth[2010];

void dfs(int v,int p,int d){
	depth[v] = d;
	for(auto &v2:grpah[v]){
		if(v2 == p) continue;
		dfs(v2, v, d + 1);
	}
}

int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;

	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		graph[a-1].push_back(b-1);
		graph[b-1].push_back(a-1);
	}


	const int inf = 1 << 20;
	int ans = inf;

	rep(i, n){
		dfs(i, -1, 0);
		int total = 0;
		rep(j, n) if(s[j] == '1') total += depth[j];
		if(total % 2 == 0) chmin(ans, total / 2);
	}

	if(ans == inf) 
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:82:17: error: 'graph' was not declared in this scope; did you mean 'grpah'?
   82 |                 graph[a-1].push_back(b-1);
      |                 ^~~~~
      |                 grpah
Language: C++

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int n;
vector<int> G[2020];
int d[2020];

void dfs(int now, int pre){
    for(auto i : G[now]){
        if(i == pre) continue;
        d[i] = d[now] + 1;
        dfs(i, now);
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    string s;
    cin >> s;
    rep(i, 0, n - 1){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    d[0] = 0;
    dfs(0, -1);
    bool f = true;
    int pl = -1;
    rep(i, 0, n){
        if(s[i] == '1'){
            if(pl == -1){
                pl = d[i] % 2;
            }else{
                if(pl != d[i] % 2){
                    f = false;
                    break;
                }
            }
        }
    }
    if(!f){
        cout << -1 << endl;
        return 0;
    }
    int e = d;
    int ans = INF;
    rep(i, 0, n){
        if(pl != e[i] % 2) continue;
        d[i] = 0;
        dfs(i, -1);
        bool g = true;
        int cnt[2020] = {};
        rep(j, 0, n){
            if(s[j] == '1'){
                if(i == j) continue;
                cnt[d[j]]++;
            }
        }
        int tmp = 0;
        rep(j, 0, 2020){
            tmp += cnt[j] * j;
        }
        if(tmp % 2) g = false;
        if(g){
            ans = min(ans, tmp / 2);
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
}


Compiler output:
a.cc: In function 'int main()':
a.cc:54:13: error: invalid conversion from 'long long int*' to 'long long int' [-fpermissive]
   54 |     int e = d;
      |             ^
      |             |
      |             long long int*
a.cc:57:19: error: invalid types 'long long int[long long int]' for array subscript
   57 |         if(pl != e[i] % 2) continue;
      |                   ^
Language: C++

#include<iostream>
#include<vector>
#include<string>

using namespace std;

typedef struct node_T
{
        vector<node_T*> neighbor;
        long long koma;
}node;

long long search(node* n, node* prev, long long len);

long long main(){
        long long n;
        cin >> n;
        node* tree = new node[n];

        string str;
        cin >> str;
        for(long long i=0;i<n;i++){
                tree[i].koma = str[i] == '0' ? 0 : 1;
        }

        for(long long i=0;i<n-1;i++){
                long long a,b;
                cin >> a >> b;
                a-=1;
                b-=1;
                tree[a].neighbor.push_back(&tree[b]);
                tree[b].neighbor.push_back(&tree[a]);
        }

        long long ans = -1;
        for(long long i=0;i<n;i++){
                long long sum = 0;
                long long max = 0;
                for(auto nx : tree[i].neighbor){
                        long long ret = search(nx, &tree[i], 1);
                        sum += ret;
                        if(max < ret){
                                max = ret;
                        }
                }

                if(sum % 2 == 0 && 2 * max <= sum){
                        //cout << "c:" << i+1 << " sum:" << sum << endl;
                        if(ans == -1 || sum/2 < ans){
                                ans = sum / 2;
                        }
                }
        }

        cout << ans << endl;
}

long long search(node* n, node* prev, long long len)
{
        long long score = len * n->koma;
        for(auto nx : n->neighbor){
                if(nx != prev){
                        score += search(nx, n, len + 1);
                }
        }
        return score;
}

Compiler output:
cc1plus: error: '::main' must return 'int'
Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int n;
string s;
int dist[2002][2002];

int main(){
	rep(i,2002)rep(j,2002)dist[i][j] = INF;
	
	scanf("%d",&n);
	cin >> s;
	s = "#"+s;
	int a[2002],b[2002];
	rep1(i,n-1){
		scanf("%d%d",&a[i],&b[i]);
	}
	
	vector<int> G[2002];
	rep1(i,n-1){
		G[a[i]].pb(b[i]);
		G[b[i]].pb(a[i]);
	}
	
	rep1(i,n){
		dist[i][i] = 0;
		queue<int> que;
		que.push(i);
		while(!que.empty()){
			int q = que.front(); que.pop();
			for(int u: G[q]){
				if(dist[i][u] != INF)continue;
				dist[i][u] = dist[i][q]+1;
				que.push(u);
			}
		}
	}
	
	/*rep1(i,n){
		rep1(j,n){
			cout << dist[i][j] << " ";
		}
		cout << endl;
	}*/
	
	int ret = INF;
	rep1(i,n){
		int c[2002] = {};
		int d[2002] = {}
		rep1(j,n){
			if(j == i)continue;
			if(s[j] == '1'){
				//cout << j << endl;
				for(int u: G[i]){
					if(dist[i][j] == dist[i][u]+dist[u][j]){
						c[u] += dist[i][j];
						d[u] ++;
						break;
					}
				}
			}
		}
		vector<int> vec;
		rep1(j,n){
			if(c[j] != 0)vec.pb(c[j]);
		}
		sor(vec);
		if(vec.size() == 0){
			cout << 0 << endl;
			return 0;
		}
		/*cout << i << endl;
		for(int u: vec){
			cout << u << " " ;
		}
		cout << endl;*/
		int sum = 0;
		for(int j = 0 ; j < vec.size() ; j ++){
			sum += vec[j];
		}
		if((sum%2) == 1)continue;
		if(vec[vec.size()-1] <= sum/2){
			ret = min( ret , sum/2 );
		}
		else {
			for(int j = 1 ; j <= n ; j ++){
				if(c[j] > sum/2 && d[j] >= 2){
					ret = min( ret , sum/2 );
				}
			}
		}
	}
	if(ret == INF)cout << -1 << endl;
	else cout << ret << endl;
}

	

Compiler output:
a.cc: In function 'int main()':
a.cc:23:19: error: expected ',' or ';' before 'for'
   23 | #define rep1(i,x) for(int i=1;i<=x;i++)
      |                   ^~~
a.cc:83:17: note: in expansion of macro 'rep1'
   83 |                 rep1(j,n){
      |                 ^~~~
a.cc:83:22: error: 'j' was not declared in this scope
   83 |                 rep1(j,n){
      |                      ^
a.cc:23:31: note: in definition of macro 'rep1'
   23 | #define rep1(i,x) for(int i=1;i<=x;i++)
      |                               ^