Problem: Example

Input

8 5
1 2
6 5
6 4
1 3
4 7


Output

11

Solution (in CPP):

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
vector<int>G[100000];

int col[100000];
pint dfs(int v,int c){
    pint ret(0,0);
    col[v]=c;
    if(c==1)ret.fi++;
    else ret.se++;
    for(auto u:G[v]){
        if(col[u]==c){
            return pint(-1001001001,0);
        }
        if(col[u]==-c)continue;
        pint p=dfs(u,-c);
        ret.fi+=p.fi;
        ret.se+=p.se;
    }
    return ret;
}

signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,M){
        int a,b;
        scanf("%lld %lld",&a,&b);
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }

    vector<pint>vec;
    rep(i,N)if(col[i]==0){
        pint p=dfs(i,1);
        if(p.fi<0){
            puts("-1");
            return 0;
        }
        vec.pb(p);
    }

    bitset<100000>bs;
    bs[0]=1;
    rep(i,vec.size()){
        bs=(bs<<vec[i].fi)|(bs<<vec[i].se);
    }

    int ma=0;
    rep(i,N)if(bs[i])chmax(ma,i*(N-i)-M);
    printf("%lld\n",ma);
    return 0;
}