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){        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);
        }绿色
        }else{绿色
            w[o]=-w[x];
            sum+=w[o];
            dfs(o,x);
        }
            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;绿色
            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 'void dfs(long long int, long long int)':
a.cc:49:50: error: 'o' was not declared in this scope
   49 |     for(int i=h[x];i!=0;i=e[i].nxt){        if(w[o]){
      |                                                  ^
a.cc:57:10: error: '\U00007eff\U00008272' was not declared in this scope
   57 |         }绿色
      |          ^~~~
a.cc:58:10: error: 'else' without a previous 'if'
   58 |         }else{绿色
      |          ^~~~
a.cc:58:15: error: '\U00007eff\U00008272' was not declared in this scope
   58 |         }else{绿色
      |               ^~~~
a.cc:60:20: error: 'o' was not declared in this scope
   60 |             sum+=w[o];
      |                    ^
a.cc:63:18: error: 'o' was not declared in this scope
   63 |             if(w[o]==w[x])
      |                  ^
a.cc:65:19: error: 'o' was not declared in this scope
   65 |             A=x,B=o;
      |                   ^
a.cc: At global scope:
a.cc:66:10: error: expected unqualified-id before 'else'
   66 |         }else{
      |          ^~~~
a.cc:71:5: error: expected declaration before '}' token
   71 |     }
      |     ^
a.cc:72:1: error: expected declaration before '}' token
   72 | }
      | ^
a.cc: In function 'int main()':
a.cc:84:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   84 |     for(register int i=0;i<m;++i){
      |                      ^
a.cc:95:22: error: '\U00007eff\U00008272' was not declared in this scope
   95 |     if(m!=n)/* 树 */{绿色
      |                      ^~~~
a.cc:111:26: error: '\U00007eff\U00008272' was not declared in this scope
  111 |                 return 0;绿色
      |                          ^~~~
a.cc:113:9: error: expected '}' before 'else'
  113 |         else
      |         ^~~~
a.cc:109:20: note: to match this '{'
  109 |             if(sum){
      |                    ^
a.cc:114:27: error: 'i' was not declared in this scope
  114 |             ans=ans+abs(w[i]);
      |                           ^
a.cc:119:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  119 |     for(register int i=1;i<=top;++i)
      |                      ^
a.cc:123:2: error: expected '}' at end of input
  123 | }
      |  ^
a.cc:82:14: note: to match this '{'
   82 | signed main(){
      |              ^