Language: C++

#include<iostream>
#include<cstdio>
#include<cstring>

namespace gg
{
	typedef long long ll;
	const int N=100100,M=N*2;
	int begin[N],next[M],to[M];
	int col[N];
	int n,m,e;
	int cnt1,cnt2;
	ll ans;
	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	bool dfs(int p,int w)
	{
		if(col[p]==w)return 1;

		if(!col[p])col[p]=w;
		else return 0;

		for(int i=begin[p];i;i=next[i])
		{
			int q=to[i];
			if(!dfs(q,3-w))return 0;
		}
		return 1;
	}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int u,v,i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			add(u,v);
		}
	}
	void work1()
	{
		cnt1=cnt2=0;
		for(int i=1;i<=n;i++)
			if(col[i]==1)cnt1++;
			else cnt2++;

		ans=(ll)cnt1*cnt2;

		printf("%lld\n",ans-m);
	}
	void work2()
	{
		ans=(ll)n*(n-1)/2;
		printf("%lld\n",ans-m);
	}
	void solve()
	{
		initialize();
		if(n<=3)
		{
			printf("0\n");
			return;
		}
		if(dfs(1,1))work1();
		else work2();
	}
}
#include<iostream>
#include<cstdio>
#include<cstring>

namespace gg
{
	typedef long long ll;
	const int N=100100,M=N*2;
	int begin[N],next[M],to[M];
	int col[N];
	int n,m,e;
	int cnt1,cnt2;
	ll ans;
	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	bool dfs(int p,int w)
	{
		if(col[p]==w)return 1;

		if(!col[p])col[p]=w;
		else return 0;

		for(int i=begin[p];i;i=next[i])
		{
			int q=to[i];
			if(!dfs(q,3-w))return 0;
		}
		return 1;
	}
	void initialize()
	{
		scanf("%d%d",&n,&m);
		for(int u,v,i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			add(u,v);
		}
	}
	void work1()
	{
		cnt1=cnt2=0;
		for(int i=1;i<=n;i++)
			if(col[i]==1)cnt1++;
			else cnt2++;

		ans=(ll)cnt1*cnt2;

		printf("%lld\n",ans-m);
	}
	void work2()
	{
		ans=(ll)n*(n-1)/2;
		printf("%lld\n",ans-m);
	}
	void solve()
	{
		initialize();
		if(n<=3)
		{
			printf("0\n");
			return;
		}
		if(dfs(1,1))work1();
		else work2();
	}
}

int main()
{
	gg::solve();
	return 0;
}

int main()
{
	gg::solve();
	return 0;
}


Compiler output:
a.cc:79:19: error: redefinition of 'const int gg::N'
   79 |         const int N=100100,M=N*2;
      |                   ^
a.cc:8:19: note: 'const int gg::N' previously defined here
    8 |         const int N=100100,M=N*2;
      |                   ^
a.cc:79:28: error: redefinition of 'const int gg::M'
   79 |         const int N=100100,M=N*2;
      |                            ^
a.cc:8:28: note: 'const int gg::M' previously defined here
    8 |         const int N=100100,M=N*2;
      |                            ^
a.cc:80:13: error: redefinition of 'int gg::begin [100100]'
   80 |         int begin[N],next[M],to[M];
      |             ^~~~~
a.cc:9:13: note: 'int gg::begin [100100]' previously declared here
    9 |         int begin[N],next[M],to[M];
      |             ^~~~~
a.cc:80:22: error: redefinition of 'int gg::next [200200]'
   80 |         int begin[N],next[M],to[M];
      |                      ^~~~
a.cc:9:22: note: 'int gg::next [200200]' previously declared here
    9 |         int begin[N],next[M],to[M];
      |                      ^~~~
a.cc:80:30: error: redefinition of 'int gg::to [200200]'
   80 |         int begin[N],next[M],to[M];
      |                              ^~
a.cc:9:30: note: 'int gg::to [200200]' previously declared here
    9 |         int begin[N],next[M],to[M];
      |                              ^~
a.cc:81:13: error: redefinition of 'int gg::col [100100]'
   81 |         int col[N];
      |             ^~~
a.cc:10:13: note: 'int gg::col [100100]' previously declared here
   10 |         int col[N];
      |             ^~~
a.cc:82:13: error: redefinition of 'int gg::n'
   82 |         int n,m,e;
      |             ^
a.cc:11:13: note: 'int gg::n' previously declared here
   11 |         int n,m,e;
      |             ^
a.cc:82:15: error: redefinition of 'int gg::m'
   82 |         int n,m,e;
      |               ^
a.cc:11:15: note: 'int gg::m' previously declared here
   11 |         int n,m,e;
      |               ^
a.cc:82:17: error: redefinition of 'int gg::e'
   82 |         int n,m,e;
      |                 ^
a.cc:11:17: note: 'int gg::e' previously declared here
   11 |         int n,m,e;
      |                 ^
a.cc:83:13: error: redefinition of 'int gg::cnt1'
   83 |         int cnt1,cnt2;
      |             ^~~~
a.cc:12:13: note: 'int gg::cnt1' previously declared here
   12 |         int cnt1,cnt2;
      |             ^~~~
a.cc:83:18: error: redefinition of 'int gg::cnt2'
   83 |         int cnt1,cnt2;
      |                  ^~~~
a.cc:12:18: note: 'int gg::cnt2' previously declared here
   12 |         int cnt1,cnt2;
      |                  ^~~~
a.cc:84:12: error: redefinition of 'gg::ll gg::ans'
   84 |         ll ans;
      |            ^~~
a.cc:13:12: note: 'gg::ll gg::ans' previously declared here
   13 |         ll ans;
      |            ^~~
a.cc:85:14: error: redefinition of 'void gg::add(int, int, bool)'
   85 |         void add(int x,int y,bool k=1)
      |              ^~~
a.cc:14:14: note: 'void gg::add(int, int, bool)' previously defined here
   14 |         void add(int x,int y,bool k=1)
      |              ^~~
a.cc:92:14: error: redefinition of 'bool gg::dfs(int, int)'
   92 |         bool dfs(int p,int w)
      |              ^~~
a.cc:21:14: note: 'bool gg::dfs(int, int)' previously defined here
   21 |         bool dfs(int p,int w)
      |              ^~~
a.cc:106:14: error: redefinition of 'void gg::initialize()'
  106 |         void initialize()
      |              ^~~~~~~~~~
a.cc:35:14: note: 'void gg::initialize()' previously defined here
   35 |         void initialize()
      |              ^~~~~~~~~~
a.cc:115:14: error: redefinition of 'void gg::work1()'
  115 |         void work1()
      |              ^~~~~
a.cc:44:14: note: 'void gg::work1()' previously defined here
   44 |         void work1()
      |              ^~~~~
a.cc:126:14: error: redefinition of 'void gg::work2()'
  126 |         void work2()
      |              ^~~~~
a.cc:55:14: note: 'void gg::work2()' previously defined here
   55 |         void work2()
      |              ^~~~~
a.cc:131:14: error: redefinition of 'void gg::solve()'
  131 |         void solve()
      |              ^~~~~
a.cc:60:14: note: 'void gg::solve()' previously defined here
   60 |         void solve()
      |              ^~~~~
a.cc:150:5: error: redefinition of 'int main()'
  150 | int main()
      |     ^~~~
a.cc:144:5: note: 'int main()' previously defined here
  144 | int main()
      |     ^~~~