Language: C++

#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,m,I,P,Q;
int cnt,head[100010],to[400010],next[400010],linker[100010];
bool f,vis[100010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	next[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa)
{
	vis[x]=true;
	linker[x]=linker[fa]^1;
	for (int i=head[x];i;i=next[i])
	{
		int y=to[i];
		if (y!=fa)
		{
			if (vis[y])
			{
				if (linker[x]==linker[y])
				{
					f=true;
				}
				continue;
			}
			else
			{
				dfs(y,x);
			}
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	int x,y;
	for (int i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	for (int i=1;i<=n;i++)
	{
		if (!vis[i])
		{
			if (head[i])
			{
				I++;
				vis[i]=true;
				continue;
			}
			f=false;
			dfs(i,0);
			if (f)
			{
				P++;
			}
			else
			{
				Q++;
			}
		}
	}
	long long ans=2LL*I*n-1LL*I*I+1LL*P*P+2LL*P*Q+2LL*Q*Q;
	printf("%lld\n",ans);
    return 0;
}

Compiler output:
a.cc: In function 'void add(int, int)':
a.cc:64:9: error: reference to 'next' is ambiguous
   64 |         next[cnt]=head[x];
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 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:58:33: note:                 'int next [400010]'
   58 | int cnt,head[100010],to[400010],next[400010],linker[100010];
      |                                 ^~~~
a.cc: In function 'void dfs(int, int)':
a.cc:71:32: error: reference to 'next' is ambiguous
   71 |         for (int i=head[x];i;i=next[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:58:33: note:                 'int next [400010]'
   58 | int cnt,head[100010],to[400010],next[400010],linker[100010];
      |                                 ^~~~