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

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
void dfs(int no,int d,int k);
vector<int> ed[100001];
int visit[100001];
int ans=0;
int main(){
int i,j;
int n,k;
cin>>n>>k;
int a[n+1];
for(i=1;i<=n;i++)
{cin>>a[i];
if(i==1){
    if(a[1]!=1)
        {a[1]=1;
        ans++;
        }

continue;
}
else
ed[a[i]].pb(i);
}

if(k<=1e5){
dfs(1,0,k);
}
cout<<ans<<endl;




return 0;
}
void dfs(int no,int d,int k){
visit[no]=1;
int i;
if(d>k)
    {
        ans++;
    d=1;
    }

for(i=0;i<ed[no].size();i++){
if(visit[ed[no[i]]==0)
    dfs(ed[no][i],d+1,k);

}




}


Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:40:1: error: reference to 'visit' is ambiguous
   40 | visit[no]=1;
      | ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:8:5: note:                 'int visit [100001]'
    8 | int visit[100001];
      |     ^~~~~
a.cc:49:4: error: reference to 'visit' is ambiguous
   49 | if(visit[ed[no[i]]==0)
      |    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:8:5: note:                 'int visit [100001]'
    8 | int visit[100001];
      |     ^~~~~
a.cc:49:15: error: invalid types 'int[int]' for array subscript
   49 | if(visit[ed[no[i]]==0)
      |               ^
a.cc:49:22: error: expected ']' before ')' token
   49 | if(visit[ed[no[i]]==0)
      |                      ^
      |                      ]
Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int N, K;
int ans;
vector<vector<int>> rev;

// int dfs(int v, int prev){
//     int depth = 0;
//     for(int to : rev[v]){
//         if(to == prev) continue;
//         depth = max(depth, 1 + dfs(to, v));
//     }
//     if(depth == K-1 && prev != 0){
//         ans++;
//         return 0;
//     }
//     return depth;
// }

int dfs(int pos, int pre) {
	int e = 0;
	for (int i : rev[pos]) {
		if (i == pre) continue;
		e = max(e, dfs(i, pos));
	}
	if (e == m - 1) {
		if(pre != 0) ans++;
		return 0;
	}
	return e + 1;
}

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

    ans = 0;
    rev.assign(N, {});
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(i == 0){
            ans += a != 1 ? 1 : 0;
        }else{
            rev[a-1].push_back(i);
        }
    }

    for (int i : rev[0]) dfs(i, 0);
    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int dfs(int, int)':
a.cc:30:18: error: 'm' was not declared in this scope
   30 |         if (e == m - 1) {
      |                  ^
Language: C++

#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/
 
struct edge {
    int next,to;
};
 
const int maxn=(int)(1e5)+5;
int a[maxn];
int fr[maxn];
edge e[maxn<<1];
int n,m,tote=0;
 
inline void addone(int u,int v) {
    ++tote;
    e[tote].next=fr[u];fr[u]=tote;e[tote].to=v;
}

inline void addedge(int u,int v) {
    addone(u,v);addone(v,u);
}
 
int res;
void dfs(int x,int f,int d) {
    RAL(i,x) if(ds[e[i].to]==ds[x]+1) {
        if(d>=m) ++res,dfs(e[i].to,x,1);
        else dfs(e[i].to,x,d+1);
    }
}
 
void bfs(int s) {
    memset(ds,-1,sizeof(ds));
    Q.push(1);ds[1]=0;
    while(!Q.empty()) {
        int x=Q.front();Q.pop();
        RAL(i,x) if(ds[e[i].to]<0) ds[e[i].to]=ds[x]+1,Q.push(e[i].to);
    }
}

int main() {
    read(n);read(m);
    REP(i,1,n) read(a[i]);
    res=(a[1]!=1);
    memset(fr,-1,sizeof(fr));
    REP(i,2,n) addedge(a[i],i);
    bfs(1);dfs(1,0,0);
    printf("%d\n",res);
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:61:17: error: 'ds' was not declared in this scope; did you mean 'd'?
   61 |     RAL(i,x) if(ds[e[i].to]==ds[x]+1) {
      |                 ^~
      |                 d
a.cc: In function 'void bfs(int)':
a.cc:68:12: error: 'ds' was not declared in this scope; did you mean 's'?
   68 |     memset(ds,-1,sizeof(ds));
      |            ^~
      |            s
a.cc:69:5: error: 'Q' was not declared in this scope
   69 |     Q.push(1);ds[1]=0;
      |     ^
Language: C++

#include<iostream>
#include<queue>
#include<functional>
using namespace std;
int n, k, a[200000], dist[200000], dist2[200000], cnt, r[200000];
vector<int>G[200000], H[200000], U[200000]; int T;
queue<pair<int, int>>Q;
vector<pair<int, int>>V;
void bfs1() {
	for (int i = 1; i <= n; i++)dist2[i] = 999999999;
	queue<int>R; R.push(1); dist2[1] = 0;
	while (!R.empty()) {
		int a1 = R.front(); R.pop();
		for (int i = 0; i < H[a1].size(); i++) {
			if (dist2[H[a1][i]] > dist2[a1] + 1) {
				dist2[H[a1][i]] = dist2[a1] + 1; R.push(H[a1][i]);
			}
		}
	}
}
void sorts() {
	for (int i = 1; i <= n; i++)dist[i] = -99999999;
	for (int i = 1; i <= n; i++) { if (r[i] == 0)V.push_back(make_pair(dist2[i], i)); }
	sort(V.begin(), V.end(), greater<pair<int, int>>());
	int maxd = V[0].first;
	while (T < V.size() && V[T].first == maxd) { Q.push(make_pair(V[T].second, maxd)); dist[V[T].second] = 0; T++; }
}
void bfs3() {
	while (!Q.empty()) {
		int a1 = Q.front().first, a2 = Q.front().second; Q.pop();
		while (T < V.size() && V[T].first == a2 - 1) { Q.push(make_pair(V[T].second, a2 - 1)); dist[V[T].second] = 0; T++; }
		for (int i = 0; i < G[a1].size(); i++) {
			int DD = dist[a1] + 1;
			if (DD == k && G[a1][i] != 1) { DD = 0; cnt++; }
			if (dist[G[a1][i]] < DD) {
				dist[G[a1][i]] = DD;
				Q.push(make_pair(G[a1][i], a2 - 1));
			}
		}
	}
}
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) { 
		cin >> a[i]; if (i != 1) { G[i].push_back(a[i]); H[a[i]].push_back(i); r[a[i]]++; }
	}
	if (a[1] != 1) { cnt++; a[1] = 1; }
	bfs1(); sorts(); bfs3();
	cout << cnt << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void sorts()':
a.cc:24:9: error: 'sort' was not declared in this scope; did you mean 'sorts'?
   24 |         sort(V.begin(), V.end(), greater<pair<int, int>>());
      |         ^~~~
      |         sorts
Language: C++

#include <stdlib.h>
#include <stdio.h>

typedef int bool;
#define true 1
#define false 0

int main(int argc, char* argv[]){
  int N, K;
  scanf("%d %d", &N, &K);
  int a[N];
  int i,j;
  for(i=0; i<N; ++i){
    scanf("%d",&a[i]);
  }
  int ans = 0;
  if(a[0] != 1){
    a[0] = 1;
    ++ans;
  }
  int count[N];
  bool counted[N];
  for(i=0; i<N; ++i){
    counted[i] = false;
  }
  count[0] = 0;
  counted[0] = true;
  bool finish = false;
  while(!finish){
    finish = true;
    for(i=0; i<N; ++i){
      if(!counted[i]){
        if(counted[a[i]-1]){
          count[i] = count[a[i]-1] + 1;
          counted[i] = true;
        }else{
          finish = false;
        }
      }
    }
  }
  //for(i=0; i<N; ++i){
  //  printf("%d\n",count[i]);
  //}
  bool connected[N];
  int maxcount = 0;
  int maxi = 0;
  bool comp = true;
  for(i=0; i<N; ++i){
    connected[i] = false;
    if(count[i] > K){
      comp = false;
    }
    if(count[i] > maxcount){
      maxcount = count[i];
      maxi = i;
    }
  }
  while(!comp){
    int p = maxi;
    for(i=0; i<K-1; ++i){
      p = a[p] - 1;
    }
    a[p] = 1;
    connected[p] = true;
    ++ans;
    finish = false;
    while(!finish){
      finish = true;
      for(i=0; i<N; ++i){
        if(!connected[i]){
          if(connected[a[i]-1]){
            connected[i] = true;
            finish = false;
          }
        }
      }
    }
    maxcount = 0;
    maxi = 0;
    for(i=0; i<N; ++i){
      if(!connected[i]){
        if(count[i] > maxcount){
          maxcount = count[i];
          maxi = i;
        }
      }
    }
    if(maxcount <= K){
      comp = true;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Compiler output:
a.cc:4:13: error: redeclaration of C++ built-in type 'bool' [-fpermissive]
    4 | typedef int bool;
      |             ^~~~
Language: Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main_Other {
    /**
     * 整数K
     */
    private static int K;

    /**
     * ある町へ転送するテレポータが設置されている町のリスト
     */
    private static List<List<Integer>> vec = new ArrayList<>();

    /**
     * 転送先を変えなければならないテレポータの数
     */
    private static int ans = 0;

    public static void main(String args[]) {
        //スタックサイズ2^24で処理を行う
        new Thread(null, () -> {
            //try-with-resources文(カッコ内で宣言した変数はtry句を抜けると自動的に閉じられる)
            try (Scanner sc = new Scanner(System.in)) {
                int n = sc.nextInt();
                K = sc.nextInt();
                for (int i = 0; i < n; i++) {
                    vec.add(new ArrayList<>());
                }
                for (int i = 0; i < n; i++) {
                    int a = sc.nextInt() - 1;
                    if (i != 0) {
                        vec.get(a).add(i);
                    } else if (a != 0) {
                        ans++;
                    }
                }
            }

            dfs(0, 0);
            System.out.println(ans);
        }, "", 1 << 24).start();
    }

    /**
     * 転送回数を算出する
     *
     * @param v   着目する町
     * @param pre 1つ前の町
     * @return 転送回数
     */
    private static int dfs(int v, int pre) {
        int height = 0;

        //拡張for文(リストや配列から要素を1つずつ取り出す)
        for (int j : vec.get(v)) {
            height = Math.max(height, dfs(j, v));
        }

        if (pre != 0 && height == K - 1) {
            height = 0;
            ans++;
        } else {
            height++;
        }

        return height;
    }
}

Compiler output:
Main.java:5: error: class Main_Other is public, should be declared in a file named Main_Other.java
public class Main_Other {
       ^
1 error
Language: Java

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    private static long K;
    private static List<List<Long>> vec;
    private static int ans;

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        K = sc.nextLong();
        ans = 0;
        vec = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            vec.add(new ArrayList<>());
        }
        for (long i = 0; i < n; i++) {
            int a = sc.nextInt() - 1;
            if (i != 0) {
                vec.get(a).add(i);
            } else if (a != 0) {
                ans++;
            }
        }
        dfs(0, 0);
        System.out.println(ans);
    }

    private static long dfs(long v, int pre) {
        long height = 0;
        for (long j : vec.get((int)v)) {
            height = Math.max(height, dfs(j, v));
        }
        if (pre != 0 && height == K - 1) {
            height = 0;
            ans++;
        } else {
            height++;
        }
        return height;
    }
}

Compiler output:
Main.java:34: error: incompatible types: possible lossy conversion from long to int
            height = Math.max(height, dfs(j, v));
                                             ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
Language: C++

#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long ll;
ll N,K,ans=0;
int a[100010];
vector<int> p[100010];

void dfs(ll h,int v) {
	
	if (h == K && a[v] != 1) {
		ans++; h = 0;
	}
	for (int i = 0; i < p[v].size(); i++) {
		dfs(h + 1, p[v][i]);
	}
}

int main() {
	cin >> N >> K;
	cin >> a[0];
	if (a[0] != 1)ans++;
	for (int i = 1; i < N; i++) {
		scanf_s("%d", &a[i]);
		p[a[i]].push_back(i);
	}
	dfs(-1, 0);
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:25:17: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   25 |                 scanf_s("%d", &a[i]);
      |                 ^~~~~~~
      |                 scanf
Language: C++


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

using namespace std;

using ll = long long;

ll n, k;
ll a[123456];
vector<ll>child[123456];
ll rem[123456];
ll ans = 0;

ll calcrem(ll v)
{
	if (rem[v] >= 0)return rem[v];
	ll ans = 0;
	if (child[v].size() == 0)
	{
		return rem[v] = 0;
	}
	else
	{
		for (ll to : child[v])
		{
			ans = max(ans, calcrem(to) + 1);
		}
	}
	return rem[v] = ans;
}

void pulltree(ll v,ll depth)
{
	if (rem[v] == k - 1 && depth != 1 && depth != 0)
	{
		++ans;
		return;
	}
	if (depth == k)
	{
		//pull
		for (ll to : child[v])
		{
			++ans;
			pulltree(to, 1);
		}
	}
	else
	{
		for (ll to : child[v])
		{
			pulltree(to, depth + 1);
		}
	}
}

ll main()
{
	scanf("%d %d", &n, &k);
	scanf("%d",a);
	if (a[0] != 1)ans += 1;
	for (ll i = 0; i < n - 1; ++i)
	{
		scanf("%d", a + i);
		--a[i];
		child[a[i]].push_back(i + 1);
	}
	memset(rem, 0xFF, sizeof(rem));
	calcrem(0);
	pulltree(0, 0);
	printf("%d\n", ans);
	return 0;
}



Compiler output:
a.cc:60:1: error: '::main' must return 'int'
   60 | ll main()
      | ^~
Language: C++

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

int n, k;
int a[100055];
int d[100055];
bool used[100055];
bool in[100055];
vector<int> rg[100055];
int tail[100055];

void dfs(int v, int dep = 0) {
	d[v] = dep;
	used[v] = true;

	for (auto u : rg[v]) {
		if (used[u]) continue;
		dfs(u, dep + 1);
	}
}
int rdfs(int v) {
	used[v] = true;

	int res = 0;

	for (auto u : rg[v]) {
		if (!used[u]) {
			res = max(res, rdfs(u) + 1);
		}
	}

	return res;
}
int go(int v, int &res) {
	int ret = 0;

	for (auto u : rg[v]) {
		ret = max(ret, go(u, res) + 1);
	}

	if (ret + 1 == k) {
		res++;
		return 0;
	}

	return ret;
}
int main() {
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		a[i]--;

		rg[a[i]].push_back(i);
	}

	dfs(0);

	bool bad = false;

	for (int i = 0; i < n; i++) {
		if (d[i] != k) {
			bad = true;
		}
	}

	if (!bad) {
		puts("0");
		return 0;
	}

	bad = false;

	for (int i = 0; i < n; i++) {
		if (d[i] > k) {
			bad = true;
		}
	}

	if (!bad) {
		printf("%d\n", a[0] != 0);
		return 0;
	}

	int res = a[0] !+ 0;

	memset(used, false, sizeof(used));

	vector<int> cycle;

	int cur = 0;

	while (!used[cur]) {
		cycle.push_back(cur);
		used[cur] = in[cur] = true;
		cur = a[cur];
	}

	cur = 0;

	reverse(cycle.begin(), cycle.end());

	for (auto v : cycle) {
		cur++;

		if (v == 0) cur = 0;
		
		if (cur > k) {
			res++;
			cur = 1;
		}

		for (auto u : rg[v]) {
			if (!in[u]) {
				tail[v] = max(tail[v], rdfs(u) + 1);
			}
		}

		if (cur + tail[v] > k) {
			bool flag = false;
			
			for (auto u : rg[v]) {
				if (!in[u]) {
					if (cur + go(u, res) + 1 > k) {
						flag = true;
					}
				}
			}

			if (flag) {
				res++;
				cur = 1;
			}
		}
	}

	printf("%d\n", res);

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:86:24: error: expected ',' or ';' before '!' token
   86 |         int res = a[0] !+ 0;
      |                        ^
Language: C++

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define x first
#define y second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

const int N=100010;

int ans,a[N],next[N],head[N];

int dfs(int k,int d)
{
    int p=head[k],t=0;
    while (p)
    {
        t=max(t,dfs(p,d)+1);
        p=next[p];
    }
    if (t==d-1&&a[k]!=1) {ans++;return -1;}
    return t;
}

int main()
{
	#ifdef waltz
		freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	int n,k;scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	ans=0;
	if (a[1]!=1) {ans++;a[1]=1;}
    for (int i=2;i<=n;i++)
        if (a[i]!=1)
        {
            next[i]=head[a[i]];head[a[i]]=i;
        }
    for (int i=2;i<=n;i++) if (a[i]==1) dfs(i,k);
    printf("%d\n",ans);
	return 0;
}


Compiler output:
a.cc: In function 'int dfs(int, int)':
a.cc:33:11: error: reference to 'next' is ambiguous
   33 |         p=next[p];
      |           ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/bits/stl_tree.h:63,
                 from /usr/include/c++/14/map:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:25:14: note:                 'int next [100010]'
   25 | int ans,a[N],next[N],head[N];
      |              ^~~~
a.cc: In function 'int main()':
a.cc:52:13: error: reference to 'next' is ambiguous
   52 |             next[i]=head[a[i]];head[a[i]]=i;
      |             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:25:14: note:                 'int next [100010]'
   25 | int ans,a[N],next[N],head[N];
      |              ^~~~
Language: C

#include <bits/stdc++.h>
using std::max;
char s[105];
int a[205][205],dp[105][105][105][105],ans,h,w,sx,sy;
int sh[105][105],sl[105][105];
#define ch(x,l,r) sh[x][r]-sh[x][l-1]
#define cl(x,l,r) sl[x][r]-sl[x][l-1]
#define m(x,y) x=max(x,y)
int main(){
	scanf("%d%d",&h,&w);
	for (int i=1;i<=h;i++) {
		scanf("%s",s+1);
		for (int j=1;j<=w;j++){
			if (s[j]=='o') a[i][j]=1;
			if (s[j]=='E') sx=i,sy=j;
		}
	}
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++) 
			sh[i][j]=a[i][j]+sh[i][j-1],sl[j][i]=a[i][j]+sl[j][i-1];
	for (int i=0;i<=h+1;i++)
		for (int j=0;j<=w+1;j++)
			for (int i2=0;i2<=h+1;i2++)
				for (int j2=0;j2<=w+1;j2++)
					dp[i][j][i2][j2]=-1;
	dp[sx][sy][sx][sy]=0;
	for (int i=sx;i>=1;i--)
		for (int j=sy;j>=1;j--)
			for (int i2=sx;i2<=h;i2++)
				for (int j2=sy;j2<=w;j2++){
					if (i==sx && i2==sx && j==sy && j2==sy) continue;
					if (dp[i+1][j][i2][j2]>=0 && i>i2-sx && i!=sx) 
						m(dp[i][j][i2][j2],dp[i+1][j][i2][j2]+ch(i,j,j2));
					if (dp[i][j][i2-1][j2]>=0 && i2<=h-(sx-i) && i2!=sx) 
						m(dp[i][j][i2][j2],dp[i][j][i2-1][j2]+ch(i2,j,j2));
					if (dp[i][j+1][i2][j2]>=0 && j>j2-sy && j!=sy) 
						m(dp[i][j][i2][j2],dp[i][j+1][i2][j2]+cl(j,i,i2));
					if (dp[i][j][i2][j2-1]>=0 && j2<=w-(sy-j) && j2!=sy) 
						m(dp[i][j][i2][j2],dp[i][j][i2][j2-1]+cl(j2,i,i2));
					ans=max(ans,dp[i][j][i2][j2]);
				}
	printf("%d\n",ans);	
}

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<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
short line[103][103],list[103][103],f[103][103][103][103],n,m,op,sx,sy;
char s[103][103];
inline short min(short a,short b){
	if(a<b) return a;
	return b;
}
inline short max(short a,short b){
	if(a>b) return a;
	return b;
}
int main(){
    cin>>n>>m;
    for(short i=1;i<=n;i++){
    	cin>>(s[i]+1);
    }
    for(short i=1;i<=n;i++){
    	for(short j=1;j<=m;j++){
        	line[i][j]=line[i][j-1]+(s[i][j]=='o');
        	list[i][j]=list[i-1][j]+(s[i][j]=='o');
        	if(s[i][j]=='E'){
        		sx=i,sy=j;
			}
    	}
	}
    for(short i=sx;i;i--){
    	for(short j=sy;j;j--){
    		for(short k=sx;k<=n;k++){
    			for(short p=sy;p<=m;p++){
        			if(1<i&&k+1<sx+i){
        				f[i-1][j][k][p]=max(f[i-1][j][k][p],f[i][j][k][p]+line[i-1][min(p,m-sy+j)]-line[i-1][max(j-1,p-sy)]);
						op=max(op,ans[i-1][j][k][p]);
					}
        			if(k<n&&sx+k<n+i){
        				f[i][j][k+1][p]=max(f[i][j][k+1][p],f[i][j][k][p]+line[k+1][min(p,m-sy+j)]-line[k+1][max(j-1,p-sy)]);
						op=max(op,ans[i][j][k+1][p]);
					}
        			if(1<j&&p+1<sy+j){
        				f[i][j-1][k][p]=max(f[i][j-1][k][p],f[i][j][k][p]+list[min(k,n-sx+i)][j-1]-list[max(i-1,k-sx)][j-1]);
						op=max(op,ans[i][j-1][k][p]);
					}
        			if(p<m&&sy+p<m+j){
        				f[i][j][k][p+1]=max(f[i][j][k][p+1],f[i][j][k][p]+list[min(k,n-sx+i)][p+1]-list[max(i-1,k-sx)][p+1]);
						op=max(op,ans[i][j][k][p+1]);
					}
    			}
			}
		}
	}
    cout<<op<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:59: error: 'ans' was not declared in this scope; did you mean 'abs'?
   36 |                                                 op=max(op,ans[i-1][j][k][p]);
      |                                                           ^~~
      |                                                           abs
a.cc:40:59: error: 'ans' was not declared in this scope; did you mean 'abs'?
   40 |                                                 op=max(op,ans[i][j][k+1][p]);
      |                                                           ^~~
      |                                                           abs
a.cc:44:59: error: 'ans' was not declared in this scope; did you mean 'abs'?
   44 |                                                 op=max(op,ans[i][j-1][k][p]);
      |                                                           ^~~
      |                                                           abs
a.cc:48:59: error: 'ans' was not declared in this scope; did you mean 'abs'?
   48 |                                                 op=max(op,ans[i][j][k][p+1]);
      |                                                           ^~~
      |                                                           abs
Language: C++

#include <bits/stdc++.h>
#define y1 __zzd001
using namespace std;
const int N=105;
int n,m,ax,ay,bx,by;
char s[N][N];
short g[N][N],dp[N][N][N][N];
short Get(int x1,int y1,int x2,int y2){
	return g[x2][y2]-g[x2][y1-1]-g[x1-1][y2]+g[x1-1][y1-1];
}
short max(short a,short b){
	return a>b?a:b;
}
short DP(int x1,int y1,int x2,int y2){
//	printf("DP %d %d %d %d\n",(int)x1,(int)y1,(int)x2,(int)y2);
	short &v=dp[x1][y1][x2][y2];
	if (~v)
		return v;
	if (x1>x2||y1>y2)
		return v=0;
	short xL=max(x2-bx+1,x1),xR=min(x1+ax-1,x2);
	short yL=max(y2-by+1,y1),yR=min(y1+ay-1,y2);
	return v=max(
			max(DP(x1,y1,x2,y2-1)+((yR==y2)?Get(xL,y2,xR,y2):0),
				DP(x1,y1+1,x2,y2)+((yL==y1)?Get(xL,y1,xR,y1):0),
			max(DP(x1,y1,x2-1,y2)+((xR==x2)?Get(x2,yL,x2,yR):0),
				DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0)));
}
int main(){
	memset(g,0,sizeof g);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (s[i][j]=='o')
				g[i][j]++;
			else if (s[i][j]=='E')
				ax=i,bx=n-i+1,ay=j,by=m-j+1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			g[i][j]=g[i][j]+g[i][j-1]+g[i-1][j]-g[i-1][j-1];
	memset(dp,-1,sizeof dp);
	printf("%d",(int)DP(1,1,n,m));
	return 0;
}

Compiler output:
a.cc: In function 'short int DP(int, int, int, int)':
a.cc:27:82: error: expected ')' before ';' token
   27 |                                 DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0)));
      |                                                                                  ^
      |                                                                                  )
a.cc:23:21: note: to match this '('
   23 |         return v=max(
      |                     ^
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
a.cc:24:7:   required from here
   24 |                         max(DP(x1,y1,x2,y2-1)+((yR==y2)?Get(xL,y2,xR,y2):0),
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   25 |                                 DP(x1,y1+1,x2,y2)+((yL==y1)?Get(xL,y1,xR,y1):0),
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   26 |                         max(DP(x1,y1,x2-1,y2)+((xR==x2)?Get(x2,yL,x2,yR):0),
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   27 |                                 DP(x1+1,y1,x2,y2)+((xL==x1)?Get(x1,yL,x1,yR):0)));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:306:17: error: '__comp' cannot be used as a function
  306 |       if (__comp(__a, __b))
      |           ~~~~~~^~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
using namespace std;
const int N=105;
char mp[N][N];
int n,m,ex,ey,ans;
int sr[N][N],sc[N][N];
int dp[N][N][N];
void mx(int &x,int y){
	x<y?x=y:0;
}
int main(){
	scanf("%d%d",&n,&m); CLR(dp,-1);
	For(i,1,n) scanf("%s",mp[i]+1);
	For(i,1,n) For(j,1,m)
		if (mp[i][j]=='o') sr[i][j]=sc[i][j]=1;
		else if (mp[i][j]=='E') ex=i,ey=j;
	For(i,1,n) For(j,1,m)
		sr[i][j]+=sr[i][j-1],
		sc[i][j]+=sc[i-1][j];
	int L=ey-1,R=m-ey,U=ex-1,D=n-ex;
	dp[0][0][0]=0;
	For(l,0,L) For(r,0,R) For(u,0,U) For(d,0,D){
		if (dp[r][u][d]==-1) continue;
		ans=max(ans,dp[r][u][d]);
		int up=max(ex-u,d+1),dn=min(ex+d,n-u);
		int le=max(ey-l,r+1),ri=min(ey+r,m-l);
		if (up>dn||le>ri) continue;
		if (u<U-d) mx(dp[r][u+1][d],dp[r][u][d]+sr[ex-u-1][ri]-sr[ex-u-1][le-1]);
		if (d<D-u) mx(dp[r][u][d+1],dp[r][u][d]+sr[ex+d+1][ri]-sr[ex+d+1][le-1]);
		if (r<R-l) mx(dp[r+1][u][d],dp[r][u][d]+sc[dn][ey+r+1]-sc[up-1][ey+r+1]);
		if (l<L-r) mx(dp[r][u][d]  ,dp[r][u][d]+sc[dn][ey-l-1]-sc[up-1][ey-l-1]);
	}
	printf("%d",ans);
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:30: error: 'CLR' was not declared in this scope
   13 |         scanf("%d%d",&n,&m); CLR(dp,-1);
      |                              ^~~
Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;

#define re return
#define in inline
#define inc(l, i, r) for(i=l; i<r; ++i)

const short mxn=1<<7;

short h, w, xe, ye, a[mxn][mxn], s[mxn][mxn], f[mxn][mxn][mxn][mxn]; char str[mxn];

in void upd(short& a, short b){a<b? a=b: 0;}

in short sum(short x1, short x2, short y1, short y2)
{re s[x2][y2]+s[x1-1][y1-1]-s[x2][y1-1]-s[x1-1][y2];}

short main()
{
    short i, j, k, l, ans=0;
    scanf("%d%d\n", &h, &w);
    inc(1, i, h+1)
    {
        scanf("%s", str);
//        gets(str);
        inc(1, j, w+1)
            switch(str[j-1])
            {
            case 'o': a[i][j]=1; break;
            case 'E': xe=i, ye=j;
            }
    }
    inc(1, i, h+1)
        inc(1, j, w+1)
        s[i][j]=a[i][j]-s[i-1][j-1]+s[i][j-1]+s[i-1][j];

    inc(0, i, xe+1)
        inc(0, j, ye+1)
        inc(0, k, h-xe+1)
        inc(0, l, w-ye+1)
    {
//        printf("%d %d %d %d : %d\n", i, j, k, l, f[i][j][k][l]);
        upd(ans, f[i][j][k][l]);
        if(i+k+1<xe)
            upd(
                f[i+1][j][k][l],
                f[i][j][k][l]+
                sum(
                    xe-i-1, xe-i-1,
                    max(ye-j, l+1), min(ye+l, w-j)
                    )
                );
        if(xe+i+k<h)
            upd(
                f[i][j][k+1][l],
                f[i][j][k][l]+
                sum(
                    xe+k+1, xe+k+1,
                    max(ye-j, l+1), min(ye+l, w-j)
                    )
                );
        if(j+l+1<ye)
            upd(
                f[i][j+1][k][l],
                f[i][j][k][l]+
                sum(
                    max(xe-i, k+1), min(xe+k, h-i),
                    ye-j-1, ye-j-1
                    )
                );
        if(ye+j+l<w)
            upd(
                f[i][j][k][l+1],
                f[i][j][k][l]+
                sum(
                    max(xe-i, k+1), min(xe+k, h-i),
                    ye+l+1, ye+l+1
                    )
                );
    }
    printf("%d\n", ans);
    re 0;
}


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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;

#define re return
#define in inline
#define inc(l, i, r) for(i=l; i<r; ++i)

const int mxn=1<<7;

int h, w, xe, ye, a[mxn][mxn], s[mxn][mxn], f[mxn][mxn][mxn][mxn]; char str[mxn];

in void upd(int& a, int b){a<b? a=b: 0;}

in int sum(int x1, int x2, int y1, int y2)
{re s[x2][y2]+s[x1-1][y1-1]-s[x2][y1-1]-s[x1-1][y2];}

int main()
{
    int i, j, k, l, ans=0;
    scanf("%d%d\n", &h, &w);
    inc(1, i, h+1)
    {
        gets(str);
        inc(1, j, w+1)
            switch(str[j-1])
            {
            case 'o': a[i][j]=1; break;
            case 'E': xe=i, ye=j;
            }
    }
    inc(1, i, h+1)
        inc(1, j, w+1)
        s[i][j]=a[i][j]-s[i-1][j-1]+s[i][j-1]+s[i-1][j];

    inc(0, i, xe+1)
        inc(0, j, ye+1)
        inc(0, k, h-xe+1)
        inc(0, l, w-ye+1)
    {
//        printf("%d %d %d %d : %d\n", i, j, k, l, f[i][j][k][l]);
        upd(ans, f[i][j][k][l]);
        if(i+k+1<xe)
            upd(
                f[i+1][j][k][l],
                f[i][j][k][l]+
                sum(
                    xe-i-1, xe-i-1,
                    max(ye-j, l+1), min(ye+l, w-j)
                    )
                );
        if(xe+i+k<h)
            upd(
                f[i][j][k+1][l],
                f[i][j][k][l]+
                sum(
                    xe+k+1, xe+k+1,
                    max(ye-j, l+1), min(ye+l, w-j)
                    )
                );
        if(j+l+1<ye)
            upd(
                f[i][j+1][k][l],
                f[i][j][k][l]+
                sum(
                    max(xe-i, k+1), min(xe+k, h-i),
                    ye-j-1, ye-j-1
                    )
                );
        if(ye+j+l<w)
            upd(
                f[i][j][k][l+1],
                f[i][j][k][l]+
                sum(
                    max(xe-i, k+1), min(xe+k, h-i),
                    ye+l+1, ye+l+1
                    )
                );
    }
    printf("%d\n", ans);
    re 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:26:9: error: 'gets' was not declared in this scope; did you mean 'getw'?
   26 |         gets(str);
      |         ^~~~
      |         getw
Language: C++

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
    x=0;int f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    x*=f;
}
inline void judge(){
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
}
/******************************head*******************************/
using namespace std;
int n, m, ex, ey;
const int N(105);
short sumr[N][N], sumc[N][N];
char st[N][N], b[N][N];
short dp[N][N][N][N];
int main() {
    read(n);read(m);
    for(int i(0); i < n; i++) {
        scanf("%s", st[i]);
        for(int j(0); j < m; j++) {
            if(st[i][j] == 'E') {
                ex = i; ey = j;
            }
        }
    }
    int ans(0);
    for(int i(0); i < n; i++) {
        for(int j(0); j < m; j++) {
            sumr[i][j] = j == 0 ? st[i][j] == 'o' : sumr[i][j - 1] + (st[i][j] == 'o');
            sumc[i][j] = i == 0 ? st[i][j] == 'o' : sumc[i - 1][j] + (st[i][j] == 'o');
        }
    }
    dp[0][0][0][0] = 0;
    for(int l(0); l <= m; l++) {
        for(int r(0); r + l <= m; r++) {
            for(int u(0); u <= n; u++) {
                for(int d(0); u + d <= n; d++) {
                    if(l + r < m) {
                        int a(max(d, ex - u)), b(min(n - 1 - u, ex + d));
                        short delta(ey + r + 1 <= m - 1 - l ? sumc[b][ey + r + 1] - (a == 0 ? 0 : sumc[a - 1][ey + r + 1]) : 0);
                        dp[l][r + 1][u][d] = max((int)dp[l][r + 1][u][d], dp[l][r][u][d] + delta);
                        delta = ey - l - 1 >= r ? sumc[b][ey - l - 1] - (a == 0 ? 0 : sumc[a - 1][ey - l - 1]) : 0;
                        dp[l + 1][r][u][d] = max((int)dp[l + 1][r][u][d], dp[l][r][u][d] + delta);
                    }
                    if(u + d < n) {
                        int a(max(r, ey - l)), b(min(m - 1 - l, ey + r));
                        short delta(ex + d + 1 <= n - 1 - u ? sumr[ex + d + 1][b] - (a == 0 ? 0 : sumr[ex + d + 1][a - 1]) : 0);
                        dp[l][r][u][d + 1] = max((int)dp[l][r][u][d + 1], dp[l][r][u][d] + delta);
                        delta = ex - u - 1 >= d ? sumr[ex - u - 1][b] - (a == 0 ? 0 : sumr[ex - u - 1][a - 1]) : 0;
                        dp[l][r][u + 1][d] = max((int)dp[l][r][u + 1][d], dp[l][r][u][d] + delta);
                    }
                }
            }
        }
    }
    for(int l(0); l <= m; l++) {
        for(int u(0); u <= n; u++) {
            ans = max(ans, (int)dp[l][m - l][u][n - u]);
        }
    }
    cout << ans << endl;
}


Compiler output:
a.cc:8:9: error: 'pair' does not name a type
    8 | typedef pair<int,int> pin;
      |         ^~~~
Language: C++

#include <iostream>
#include <algorithm>
#include <cmath.h>
using namespace std;
#define int long long
void read(int &x) {
    int r = 0, ne = 1;
    char c;
    while (c < '0' || c > '9') {
     chtholly2317   if (c == '-')
            ne = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        r = r * 10 + c - '0';
        c = getchar();
    }
    x = r * ne;
}
struct Edge {
    /* data */
    int i, nxt;
};
/* 链表 */
int h[100002], tot;
Edge e[200002];
inline void _add(int x, int y) {/*无向边*/
    e[++tot].i = y;
    e[tot].nxt = h[x];
    h[x] = tot;
    e[tot++].i = x;
    e[tot].nxt = h[y];
    h[y] = tot;
}
/* 输入 */
int n, m, x, y;
/* 偶环-求解 */
int s[100002], top, mid;
/* dfs */
bool odd;                             /* 奇环 */
int A, B;                             /* 环两个连接点 */
int w[100002]; /* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */
int k[100002];                        /* 偶环时标记多余边到LCA的点 */
int sum;                              /* 权值总和 */
int ans;                              /* 答案 */
inline void dfs(int x, int fa) { /* 染色 */
    for (int i = h[x]; i != 0; i = e[i].nxt) {
        int o = e[i].i;
        if (o == fa)
            continue;
        if (w[o]) {
            if (w[o] == w[x])
                odd = true;
            A = x, B = o;
        }
        else {
            w[o] = -w[x];
            sum += w[o];
            dfs(o, x);
        }
    }
}
inline void Dfs(int x, int fa) { /* 求解 */
    for (int i = h[x]; i != 0; i = e[i].nxt) {
        int o = e[i].i;
        if (o == fa || (o == A && x == B) || (o == B && x == A))
            continue; /* 拆掉基环树成为树先做 */
        Dfs(o, x);
        w[x] += w[o];
        k[x] += k[o];
    }
}
signed main() {
    read(n), read(m);
    for (register int i = 0; i < m; ++i) {
        read(x), read(y);
        _add(x, y);
    }
    if (n % 2) {
        puts("-1");
        return 0;
    }
    w[1] = 1;
    sum = 1;
    dfs(1, 0);
    if (m != n) /* 树 */ {
        if (sum) {
            puts("-1");
            return 0;
        }
    } else {
        if (odd) /* 奇环 */ {
            if (sum & 1) {//奇环最后那条边可以将sum加减2，所以sum只要是偶数就可以满足
                puts("-1");
                return 0;
            }
            ans += abs(sum / 2);
            w[A] -= sum / 2, w[B] -= sum / 2;
            //这两行预处理奇环对sum的改变
        } else /* 偶环 */ {
            if (sum) {
                puts("-1");
                return 0;
            }
            k[A] = 1, k[B] = -1;//用于标记偶环树环上的点
        }
    }
    Dfs(1, 0);
    for (register int i = 1; i <= n; ++i) {
        if (k[i])
            s[++top] = k[i] * w[i];
        else
            ans = ans + abs(w[i]);
    }
    s[++top] = 0;
    sort(s + 1, s + top + 1);
    mid = s[(top + 1) / 2];
    for (register int i = 1; i <= top; ++i)
        ans += abs(s[i] - mid);
    printf("%lld\n", ans);
    return 0;
}

Compiler output:
a.cc:3:10: fatal error: cmath.h: No such file or directory
    3 | #include <cmath.h>
      |          ^~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
// #define int long long
void read(int &x)
{
    int r = 0, ne = 1;
    char c;
    while (c < '0' || c > '9')
    {
        if (c == '-')
            ne = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        r = r * 10 + c - '0';
        c = getchar();
    }
    x = r * ne;
}
struct  Edge
{
    /* data */
    int i,nxt;
};
/* 链表 */
int h[100002],tot;
Edge e[200002];
inline void _add(int x,int y){
    e[++tot].i=y;
    e[tot].nxt=h[x];
    h[x]=tot;
    e[++tot].i=x;
    e[tot].nxt=h[y];
    h[y]=tot;
}
/* 输入 */
int n,m,x,y;
/* 偶环-求解 */
int s[100002],top,mid;
/* dfs */
bool odd;/* 奇环 */
int A,B;/* 环两个连接点 */
int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */
int k[100002];/* 偶环时标记多余边到LCA的点 */
int sum;/* 权值总和 */
long long ans;/* 答案 */
void dfs(int x,int fa){/* 染色 */
    for(int i=h[x];i;i=e[i].nxt){      
        int o=e[i].i;
        if(o==fa)continue;
        if(w[o]){
            if(w[o]==w[x])
                odd=true;
            A=x,B=o;
        }else{
            w[o]=-w[x];
            // sum+=w[o];
            dfs(o,x);
        }
    }
}
void Dfs(int x,int fa){/* 求解 */
    for(int i=h[x];i!=0;i=e[i].nxt){
        int o=e[i].i;
        if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */
        Dfs(o,x);
        w[x]+=w[o];
        k[x]+=k[o];
    }
}
signed main(){
    read(n),read(m);
    for(register int i=0;i<m;++i){
        read(x),read(y);
        _add(x,y);
    }
    // if(n%2){
    //     puts("-1");
    //     return 0;
    // }
    w[1]=1;
    // sum=1;
    dfs(1,0);
    for(int i=1;i<=n;++i)sum+=w[i];    
    if(m+1==n)/* 树 */{
        if(sum){
            puts("-1");
           return 0;
        }
    }else{
        if(odd)/* 奇环 */{
            if(sum&1){
                puts("-1");
                return 0;
            }
            ans+=abs(sum>>1);
            w[A]-=sum>>1,w[B]-=sum>>1;
        }else/* 偶环 */{
            if(sum){
                puts("-1");
                return 0;
            }else 
                k[A]=1,k[B]=-1;
        }
    }
    Dfs(1,0);
    for(register int i=1;i<=n;++i){
        if(k[i])
            s[++top]=k[i]*w[i];
        else
            ans+=ansabs(w[i]);
    }
    s[++top]=0;
    sort(s+1,s+top+1);
    mid=s[(top+1)>>1];
    for(register int i=1;i<=top;++i)
        ans+=abs(s[i]-mid);
    printf("%lld\n",ans);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   74 |     for(register int i=0;i<m;++i){
      |                      ^
a.cc:108:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  108 |     for(register int i=1;i<=n;++i){
      |                      ^
a.cc:112:18: error: 'ansabs' was not declared in this scope
  112 |             ans+=ansabs(w[i]);
      |                  ^~~~~~
a.cc:117:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  117 |     for(register int i=1;i<=top;++i)
      |                      ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
void read(int &x)
{
    int r = 0, ne = 1;
    char c;
    while (c < '0' || c > '9')
    {
        if (c == '-')
            ne = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        r = r * 10 + c - '0';
        c = getchar();
    }
    x = r * ne;
}
struct  Edge
{
    /* data */
    int i,nxt;
};
/* 链表 */
int h[100002],tot=1;
Edge e[200002];
inline void _add(int x,int y){
    e[tot].i=y;
    e[tot].nxt=h[x];
    h[x]=tot++;
    e[tot].i=x;
    e[tot].nxt=h[y];
    h[y]=tot++;
}
/* 输入 */
int n,m,x,y;
/* 偶环-求解 */
int s[100002],top,mid;
/* dfs */
bool odd;/* 奇环 */
int A,B;/* 环两个连接点 */
int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */
int k[100002];/* 偶环时标记多余边到LCA的点 */
int sum;/* 权值总和 */
int ans;/* 答案 */
inline void dfs(int x,int fa){/* 染色 */
    for(int i=h[x];i!=0;i=e[i].nxt){      
        int o=e[i].i;
        if(o==fa)continue;
        if(w[o]){
            if(w[o]==w[x])
                odd=true;
            A=x,B=o;
        }else{
            w[o]=-w[x];
            sum+=w[o];
            dfs(o,x);
        }
    }
}
inline void Dfs(int x,int fa){/* 求解 */
    for(int i=h[x];i!=0;i=e[i].nxt){
        int o=e[i].i;
        if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */
        Dfs(o,x);
        w[x]+=w[o];
        k[i]+=k[o];
    }
}
signed main(){
    read(n),read(m);
    for(register int i=0;i<m;++i){
        read(x),read(y);
        _add(x,y);
    }
    if(n%2){
        puts("-1");
        return 0;
    }
    w[1]=1;
    sum=1;
    dfs(1,0);    
    if(m!=n)/* 树 */{
        if(sum){
            puts("-1");
           return 0;
        }
    }else{
        if(odd)/* 奇环 */{
            if(sum&1){
                puts("-1");
                return 0;
            }
            ans+=abs(sum/2);
            w[A]-=sum/2,w[B]-=sum/2;
        }else/* 偶环 */{
            if(sum){
                puts("-1");
                return 0;
            }else 
                k[A]=1,k[B]=-1;
    }
    Dfs(1,0);
    for(register int i=1;i<=n;++i){
        if(k[i])
            s[++top]=k[i]*w[i];
        else
            ans=ans+abs(w[i]);
    }
    s[++top]=0;
    sort(s+1,s+top+1);
    mid=s[(top+1)/2];
    for(register int i=1;i<=top;++i)
        ans+=abs(s[i]-mid);
    printf("%lld\n",ans);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:74:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   74 |     for(register int i=0;i<m;++i){
      |                      ^
a.cc:106:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  106 |     for(register int i=1;i<=n;++i){
      |                      ^
a.cc:115:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  115 |     for(register int i=1;i<=top;++i)
      |                      ^
a.cc:119:2: error: expected '}' at end of input
  119 | }
      |  ^
a.cc:72:14: note: to match this '{'
   72 | signed main(){
      |              ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
void read(int &x)
{
    int r = 0, ne = 1;
    char c;
    while (c < '0' || c > '9')
    {
        if (c == '-')
            ne = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
    {
        r = r * 10 + c - '0';
        c = getchar();
    }
    x = r * ne;
}
struct  Edge
{
    /* data */
    int i,nxt;
};
/* 链表 */
int h[100002],tot=1;
Edge e[200002];
inline void _add(int x,int y){
    e[tot].i=y;
    e[tot].nxt=h[x];
    h[x]=tot++;
    e[tot].i=x;
    e[tot].nxt=h[y];
    h[y]=tot++;
}
/* 输入 */
int n,m,x,y;
/* 偶环-求解 */
int s[100002],top,mid;
/* dfs */
bool odd;/* 奇环 */
int A,B;/* 环两个连接点 */
int w[100002];/* 点绿色权值(1,-1) */ /* 第二遍扫时存的是子树总权值 */
int k[100002];/* 偶环时标记多余边到LCA的点 */
int sum;/* 权值总和 */
int ans;/* 答案 */
inline void dfs(int x,int fa){/* 染色 */
    for(int i=h[x];i!=0;i=e[i].nxt){      
        int o=e[i].i;
        if(w[o]==w[x]){
            odd=true;
            A=x,B=o;
        }else{
            w[o]=-w[x];
            sum+=w[o];
            dfs(o,x);
        }
    }
}
inline void Dfs(int x,int fa){/* 求解 */
    for(int i=h[x];i!=0;i=e[i].nxt){
        int o=e[i].i;
        if(o==fa||(o==A&&x==B)||(o==B&&x==A))continue;/* 排除基环树的干扰 */
        Dfs(o,x);
        w[x]+=w[o];
        k[i]+=k[o];
    }
}
signed main(){
    read(n),read(m);
    for(register int i=0;i<m;++i){
        read(x),read(y);
        _add(x,y);
    }
    if(n%2){
        puts("-1");
        return 0;
    }
    w[1]=1;
    sum=1;
    dfs(1,0);    
    if(m!=n)/* 树 */{
        if(sum){
            puts("-1");
           return 0;
        }
    }else{
        if(odd)/* 奇环 */{
            if(sum&1){
                puts("-1");
                return 0;
            }
            ans+=abs(sum/2);
            w[A]-=sum/2,w[B]-=sum/2;
        }else/* 偶环 */{
            if(sum){
                puts("-1");
                return 0;
            }else 
                k[A]=1,k[B]=-1;
    }
    Dfs(1,0);
    for(register int i=1;i<=n;++i){
        if(k[i])
            s[++top]=k[i]*w[i];
        else
            ans=ans+abs(w[i]);
    }
    s[++top]=0;
    sort(s+1,s+top+1);
    mid=s[(top+1)/2];
    for(register int i=1;i<=top;++i)
        ans+=abs(s[i]-mid);
    printf("%lld\n",ans);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   72 |     for(register int i=0;i<m;++i){
      |                      ^
a.cc:104:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  104 |     for(register int i=1;i<=n;++i){
      |                      ^
a.cc:113:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  113 |     for(register int i=1;i<=top;++i)
      |                      ^
a.cc:117:2: error: expected '}' at end of input
  117 | }
      |  ^
a.cc:70:14: note: to match this '{'
   70 | signed main(){
      |              ^