stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;

typedef vector<int> VI;

typedef vector<VI> VVI;

typedef vector<ll> VL;

typedef vector<VL> VVL;

typedef pair<int, int> PII;



#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)

#define ALL(x) x.begin(), x.end()

#define MOD 1000000007

#define INF (1LL<<25)     //33554432

#define PI 3.14159265359

#define EPS 1e-12

//#define int ll



VI g[100010];

int n, m, color[100010], d = 0;

bool e = true;



void dfs(int v, int c) {

  color[v] = c;

  d++;

  for(int i: g[v]) {

    if(color[i] == 0)

      dfs(i, -c);

    if(color[i] == c)

      e = false;

  }

}



signed main(void)

{

  cin >> n >> m;

  REP(i, m) {

    int u, v;

    cin >> u >> v;

    g[u-1].push_back(v-1);

    g[v-1].push_back(u-1);

  }



  ll a = 0, b = 0, c = 0;

  REP(i, n) {

    d = 0; e = true;

    if(color[i] == 0) {

      dfs(i, 1);

      if(d == 1) a++;

      else if(e) b++;

      else c++;

    }

  }

  //cout << a << " " << b << " " << c << endl;

  cout << 2*b*b + 2*b*c + c*c + a*a + 2*a*(n-a) << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.4516701648670645x):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)

#define REP(i, n) FOR(i, 0, n)

#define ALL(x) x.begin(), x.end()

template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }

template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }

struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;

#ifdef DEBUG_ 

#include "../program_contest_library/memo/dump.hpp"

#else

#define dump(...)

#endif

const ll INF = 1LL<<60;



int main(void) {

    ll n, m;

    cin >> n >> m;

    vector<vector<ll>> g(n);

    REP(i, m) {

        ll a, b;

        cin >> a >> b;

        a--, b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }



    dump(g);



    bool flag;

    vector<ll> col(n, -1);

    function<void(ll,ll)> dfs = [&](ll v, ll c) {

        col[v] = c;

        for(auto to: g[v]) {

            if(col[to] == c) flag = false;

            if(col[to] == -1) dfs(to, 1-c);

        }

    };

    ll x = 0, y = 0, z = 0;

    REP(i, n) {

        if(g[i].size() == 0) z++;

        else if(col[i] == -1) {

            flag = true;

            dfs(i, 0);

            if(flag) x++;

            else y++;

        }

    }

    dump(x, y, z);

    cout << 2*x*x + 2*x*y + y*y + z*z + 2*z*(n-z) << endl;



    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100005,maxm=400005;

int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;

void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}

int main(){

	int n,m,x,y;

	while(cin>>n>>m){

		ll I=0,P=0,Q=0;

		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));

		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));

		for(int i=1;i<=m;++i){

				scanf("%d%d",&x,&y);add(x,y);add(y,x);

		}

		for(int i=1;i<=n;++i)if(!vis[i]){

				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;

				bool flag=1;

				while(head<tail){

    	              int u=q[++head];

    	              for(int j=last[u];j;j=pre[j]){

    	                     int v=other[j];

    	                     if(!vis[v]){

            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;

           	              	 }

							 else{

								 if((cal[v]-cal[u])%2==0)flag=0;

							 }

                       }

	            }

	  			if(head==1){++I;continue;}

	  			if(flag)++Q;

	  			else ++P;

		}

		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;

    }

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4679616872138674x):
#include<cstdio>

#include<vector>

#include<algorithm>

using namespace std;

const int MAXN=100005;



int n,m;

vector<int> adj[MAXN];

int col[MAXN];



bool dfs(int u,int color)

{

	if(col[u])

		return color==col[u];

	col[u]=color;

	bool ret=true;

	for(int i=0;i<(int)adj[u].size();i++)

	{

		int v=adj[u][i];

		if(!dfs(v,color==1?2:1))

			ret=false;

	}

	return ret;

}



int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	int a=0,b=0,c=0;

	for(int i=1;i<=n;i++)

		if(!col[i])

		{

			if(adj[i].size()==0U)

				c++,col[i]=1;

			else

			{

				if(dfs(i,1))

					a++;

				else

					b++;

			}

		}

	long long ans=1LL*c*c+2LL*c*(n-c)+2LL*a*a+2LL*a*b+1LL*b*b;

	printf("%lld\n",ans);



	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100005,maxm=400005;

int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;

void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}

int main(){

	int n,m,x,y;

	while(cin>>n>>m){

		ll I=0,P=0,Q=0;

		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));

		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));

		for(int i=1;i<=m;++i){

				scanf("%d%d",&x,&y);add(x,y);add(y,x);

		}

		for(int i=1;i<=n;++i)if(!vis[i]){

				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;

				bool flag=1;

				while(head<tail){

    	              int u=q[++head];

    	              for(int j=last[u];j;j=pre[j]){

    	                     int v=other[j];

    	                     if(!vis[v]){

            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;

           	              	 }

							 else{

								 if((cal[v]-cal[u])%2==0)flag=0;

							 }

                       }

	            }

	  			if(head==1){++I;continue;}

	  			if(flag)++Q;

	  			else ++P;

		}

		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;

    }

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 26.26312471211229x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define SF scanf

#define PF printf

#define MAXN 100010

using namespace std;

typedef long long ll;

struct node{

	int x;

	node *nxt;	

}edge[MAXN*4];

node *head[MAXN],*ncnt=edge;

void add_edge(int u,int v){

	++ncnt;

	ncnt->x=v;

	ncnt->nxt=head[u];

	head[u]=ncnt;	

}

int fa[MAXN],n,m,tag[MAXN],dep[MAXN],siz[MAXN],tot;

int get_fa(int x){

	if(fa[x]==0)

		return x;

	fa[x]=get_fa(fa[x]);

	return fa[x];	

}

pair<int,int> l[MAXN*2];

void dfs(int x,int f){

	dep[x]=dep[f]^1;

	for(node *v=head[x];v!=NULL;v=v->nxt){

		int u=v->x;

		if(u==f)

			continue;

		dfs(u,x);

	}

}

ll cnt[2];

int main(){

	int u,v;

	SF("%d%d",&n,&m);

	for(int i=1;i<=n;i++)

		siz[i]=1;

	for(int i=1;i<=m;i++){

		SF("%d%d",&u,&v);

		if(get_fa(u)!=get_fa(v)){	

			add_edge(u,v);

			add_edge(v,u);

			u=get_fa(u);

			v=get_fa(v);

			fa[u]=v;

			siz[v]+=siz[u];

		}

		else

			l[++tot]=make_pair(u,v);

	}

	for(int i=1;i<=n;i++)

		if(fa[i]==0)

			dfs(i,0);

	for(int i=1;i<=tot;i++)

		if(dep[l[i].first]==dep[l[i].second])

			tag[get_fa(l[i].first)]=1;	

	ll ans=0,poi=0;

	for(int i=1;i<=n;i++)

		if(fa[i]==0){

			if(siz[i]==1){

				ans+=n;

				poi++;

			}

			else

				cnt[tag[i]]++;

		}

	ans+=(n-poi)*poi;

	ans+=cnt[1]*(cnt[1]+cnt[0]*2ll);

	ans+=cnt[0]*cnt[0]*2ll;

	PF("%lld",ans);

		

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>

using namespace std;

const int MAXN=100005;



int n,m;

vector<int> adj[MAXN];

int col[MAXN];



bool dfs(int u,int color)

{

	if(col[u])

		return color==col[u];

	col[u]=color;

	bool ret=true;

	for(int i=0;i<(int)adj[u].size();i++)

	{

		int v=adj[u][i];

		if(!dfs(v,color==1?2:1))

			ret=false;

	}

	return ret;

}



int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	int a=0,b=0,c=0;

	for(int i=1;i<=n;i++)

		if(!col[i])

		{

			if(adj[i].size()==0U)

				c++,col[i]=1;

			else

			{

				if(dfs(i,1))

					a++;

				else

					b++;

			}

		}

	long long ans=1LL*c*c+2LL*c*(n-c)+2LL*a*a+2LL*a*b+1LL*b*b;

	printf("%lld\n",ans);



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 17.890878856626465x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#include<cmath>

#define SF scanf

#define PF printf

#define MAXN 100010

using namespace std;

typedef long long ll;

struct node{

	int x;

	node *nxt;	

}edge[MAXN*4];

node *head[MAXN],*ncnt=edge;

void add_edge(int u,int v){

	++ncnt;

	ncnt->x=v;

	ncnt->nxt=head[u];

	head[u]=ncnt;	

}

int fa[MAXN],n,m,tag[MAXN],dep[MAXN],siz[MAXN],tot;

int get_fa(int x){

	if(fa[x]==0)

		return x;

	fa[x]=get_fa(fa[x]);

	return fa[x];	

}

pair<int,int> l[MAXN*2];

void dfs(int x,int f){

	dep[x]=dep[f]^1;

	for(node *v=head[x];v!=NULL;v=v->nxt){

		int u=v->x;

		if(u==f)

			continue;

		dfs(u,x);

	}

}

ll cnt[2];

int main(){

	int u,v;

	SF("%d%d",&n,&m);

	for(int i=1;i<=n;i++)

		siz[i]=1;

	for(int i=1;i<=m;i++){

		SF("%d%d",&u,&v);

		if(get_fa(u)!=get_fa(v)){	

			add_edge(u,v);

			add_edge(v,u);

			u=get_fa(u);

			v=get_fa(v);

			fa[u]=v;

			siz[v]+=siz[u];

		}

		else

			l[++tot]=make_pair(u,v);

	}

	for(int i=1;i<=n;i++)

		if(fa[i]==0)

			dfs(i,0);

	for(int i=1;i<=tot;i++)

		if(dep[l[i].first]==dep[l[i].second])

			tag[get_fa(l[i].first)]=1;	

	ll ans=0,poi=0;

	for(int i=1;i<=n;i++)

		if(fa[i]==0){

			if(siz[i]==1){

				ans+=n;

				poi++;

			}

			else

				cnt[tag[i]]++;

		}

	ans+=(n-poi)*poi;

	ans+=cnt[1]*(cnt[1]+cnt[0]*2ll);

	ans+=cnt[0]*cnt[0]*2ll;

	PF("%lld",ans);

		

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100005,maxm=400005;

int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;

void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}

int main(){

	int n,m,x,y;

	while(cin>>n>>m){

		ll I=0,P=0,Q=0;

		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));

		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));

		for(int i=1;i<=m;++i){

				scanf("%d%d",&x,&y);add(x,y);add(y,x);

		}

		for(int i=1;i<=n;++i)if(!vis[i]){

				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;

				bool flag=1;

				while(head<tail){

    	              int u=q[++head];

    	              for(int j=last[u];j;j=pre[j]){

    	                     int v=other[j];

    	                     if(!vis[v]){

            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;

           	              	 }

							 else{

								 if((cal[v]-cal[u])%2==0)flag=0;

							 }

                       }

	            }

	  			if(head==1){++I;continue;}

	  			if(flag)++Q;

	  			else ++P;

		}

		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;

    }

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 26.300133258582676x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXN 200010

#define LL long long

int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c;

void AddEdge(int u,int v)

{

	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;

}

int dep[MAXN],f,dcnt,cnt1,cnt2,cnt3,n,m;

void dfs(int u)

{

	dcnt++;

	for(int i=Adj[u];i;i=nxt[i])

		if(!dep[V[i]])

		{

			dep[V[i]]=dep[u]+1;

			dfs(V[i]);

		}

		else if(dep[V[i]]%2==dep[u]%2)

			f=1;

}

int main()

{

	scanf("%d%d",&n,&m);

	int u,v;

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&u,&v);

		AddEdge(u,v);

		AddEdge(v,u);

	}

	for(int i=1;i<=n;i++)

		if(!dep[i])

		{

			f=0,dcnt=0;

			dep[i]=1;

			dfs(i);

			if(f) cnt1++;

			else if(dcnt>1) cnt2++;

			else cnt3++;

		}

	LL ans=1LL*cnt1+cnt2*2LL+2LL*cnt1*cnt2+1LL*cnt1*(cnt1-1)+2LL*cnt2*(cnt2-1)+2LL*cnt3*n-1LL*cnt3*cnt3;

	printf("%lld\n",ans);

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>

using namespace std;

const int MAXN=100005;



int n,m;

vector<int> adj[MAXN];

int col[MAXN];



bool dfs(int u,int color)

{

	if(col[u])

		return color==col[u];

	col[u]=color;

	bool ret=true;

	for(int i=0;i<(int)adj[u].size();i++)

	{

		int v=adj[u][i];

		if(!dfs(v,color==1?2:1))

			ret=false;

	}

	return ret;

}



int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	int a=0,b=0,c=0;

	for(int i=1;i<=n;i++)

		if(!col[i])

		{

			if(adj[i].size()==0U)

				c++,col[i]=1;

			else

			{

				if(dfs(i,1))

					a++;

				else

					b++;

			}

		}

	long long ans=1LL*c*c+2LL*c*(n-c)+2LL*a*a+2LL*a*b+1LL*b*b;

	printf("%lld\n",ans);



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 17.916089696114124x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXN 200010

#define LL long long

int Adj[MAXN],V[MAXN*2],nxt[MAXN*2],c;

void AddEdge(int u,int v)

{

	c++;V[c]=v,nxt[c]=Adj[u];Adj[u]=c;

}

int dep[MAXN],f,dcnt,cnt1,cnt2,cnt3,n,m;

void dfs(int u)

{

	dcnt++;

	for(int i=Adj[u];i;i=nxt[i])

		if(!dep[V[i]])

		{

			dep[V[i]]=dep[u]+1;

			dfs(V[i]);

		}

		else if(dep[V[i]]%2==dep[u]%2)

			f=1;

}

int main()

{

	scanf("%d%d",&n,&m);

	int u,v;

	for(int i=1;i<=m;i++)

	{

		scanf("%d%d",&u,&v);

		AddEdge(u,v);

		AddEdge(v,u);

	}

	for(int i=1;i<=n;i++)

		if(!dep[i])

		{

			f=0,dcnt=0;

			dep[i]=1;

			dfs(i);

			if(f) cnt1++;

			else if(dcnt>1) cnt2++;

			else cnt3++;

		}

	LL ans=1LL*cnt1+cnt2*2LL+2LL*cnt1*cnt2+1LL*cnt1*(cnt1-1)+2LL*cnt2*(cnt2-1)+2LL*cnt3*n-1LL*cnt3*cnt3;

	printf("%lld\n",ans);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100005,maxm=400005;

int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;

void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}

int main(){

	int n,m,x,y;

	while(cin>>n>>m){

		ll I=0,P=0,Q=0;

		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));

		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));

		for(int i=1;i<=m;++i){

				scanf("%d%d",&x,&y);add(x,y);add(y,x);

		}

		for(int i=1;i<=n;++i)if(!vis[i]){

				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;

				bool flag=1;

				while(head<tail){

    	              int u=q[++head];

    	              for(int j=last[u];j;j=pre[j]){

    	                     int v=other[j];

    	                     if(!vis[v]){

            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;

           	              	 }

							 else{

								 if((cal[v]-cal[u])%2==0)flag=0;

							 }

                       }

	            }

	  			if(head==1){++I;continue;}

	  			if(flag)++Q;

	  			else ++P;

		}

		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;

    }

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4672731012471993x):
#include<cstdio>

#include<algorithm>

#include<vector>

using namespace std;



#define x first

#define y second

typedef pair<int,int> pii;

typedef long long ll;

const int MAXN=100005;



int n,m;

int co[MAXN];

bool vis[MAXN];

vector<int> E[MAXN];



bool dfs(int u){

    bool tag=1;

    vis[u]=1;

    for(int i=0;i<(int)E[u].size();i++){

        int v=E[u][i];

        if(vis[v]) tag&=(co[v]!=co[u]);

        else{

            co[v]=co[u]^1;

            tag&=dfs(v);

        }

    }

    return tag;

}



int main(){

    //freopen("squared.in","r",stdin);

    //freopen("squared.out","w",stdout);



    scanf("%d%d",&n,&m);

    for(int i=1;i<=m;i++){

        int u,v;

        scanf("%d%d",&u,&v);

        E[u].push_back(v);

        E[v].push_back(u);

    }

    int cnt=0,p=0,q=0;

    for(int i=1;i<=n;i++){

        if(vis[i]) continue;

        if(!E[i].size()) cnt++;

        else{

            if(dfs(i)) q++;

            else p++;

        }

    }

    printf("%lld\n",(ll)cnt*cnt+2ll*cnt*(n-cnt)+p*p+2ll*p*q+2ll*q*q);



    fclose(stdin);

    fclose(stdout);

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100005,maxm=400005;

int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;

void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}

int main(){

	int n,m,x,y;

	while(cin>>n>>m){

		ll I=0,P=0,Q=0;

		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));

		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));

		for(int i=1;i<=m;++i){

				scanf("%d%d",&x,&y);add(x,y);add(y,x);

		}

		for(int i=1;i<=n;++i)if(!vis[i]){

				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;

				bool flag=1;

				while(head<tail){

    	              int u=q[++head];

    	              for(int j=last[u];j;j=pre[j]){

    	                     int v=other[j];

    	                     if(!vis[v]){

            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;

           	              	 }

							 else{

								 if((cal[v]-cal[u])%2==0)flag=0;

							 }

                       }

	            }

	  			if(head==1){++I;continue;}

	  			if(flag)++Q;

	  			else ++P;

		}

		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;

    }

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.467398803800426x):
#include<cstdio>

#include<cstring>

#include<vector>

#include<algorithm>

using namespace std;

const long long MAXN=100005;

long long n,m;

vector<int>w[MAXN];

bool vis[MAXN];

long long cl[MAXN];

bool dfs(long long u)

{

	vis[u]=1;

	long long re=1;

	for(long long i=0;i<int(w[u].size());i++)

	{

		long long v=w[u][i];

		if(vis[v])

			re&=(cl[u]!=cl[v]);

		else

		{

			cl[v]=cl[u]^1;

			re&=dfs(v);

		}

	}

	return re;

}

int main()

{

	//freopen("squared.in","r",stdin);

	//freopen("squared.out","w",stdout);

	scanf("%lld %lld",&n,&m);

	for(long long i=1;i<=m;i++)

	{

		long long u,v;

		scanf("%lld %lld",&u,&v);

		w[u].push_back(v);

		w[v].push_back(u);

	}

	long long I=0,O=0,J=0;

	for(long long i=1;i<=n;i++)

	{

		if(!vis[i])

		{

			if(int(w[i].size())==0)

				I++;

			else if(dfs(i))

				O++;

			else

				J++;

		}

	}

	printf("%lld\n",I*I+I*(n-I)*2+O*O*2+J*J+O*J*2);

	fclose(stdin);

	fclose(stdout);;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

using namespace std;

typedef long long ll;

const int maxn=100005,maxm=400005;

int last[maxn],pre[maxm],other[maxm],t,cal[maxn],vis[maxn],q[maxn],head,tail;

void add(int x,int y){++t;pre[t]=last[x];last[x]=t;other[t]=y;}

int main(){

	int n,m,x,y;

	while(cin>>n>>m){

		ll I=0,P=0,Q=0;

		memset(last,0,sizeof(last));t=0;memset(vis,0,sizeof(vis));

		memset(pre,0,sizeof(pre));memset(other,0,sizeof(other));

		for(int i=1;i<=m;++i){

				scanf("%d%d",&x,&y);add(x,y);add(y,x);

		}

		for(int i=1;i<=n;++i)if(!vis[i]){

				head=tail=0;q[++tail]=i;cal[i]=0;vis[i]=1;

				bool flag=1;

				while(head<tail){

    	              int u=q[++head];

    	              for(int j=last[u];j;j=pre[j]){

    	                     int v=other[j];

    	                     if(!vis[v]){

            	                q[++tail]=v;vis[v]=1;cal[v]=cal[u]+1;

           	              	 }

							 else{

								 if((cal[v]-cal[u])%2==0)flag=0;

							 }

                       }

	            }

	  			if(head==1){++I;continue;}

	  			if(flag)++Q;

	  			else ++P;

		}

		cout<<2ll*I*n-I*I+P*P+2ll*P*Q+2ll*Q*Q<<endl;

    }

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 26.31906670640378x):
#include<cstdio>

#define maxn 100005

#define maxm 200005

int n,m,ia,pa,qa;

bool f,val[maxn],vis[maxn];

struct node { int v; node *nxt; } edge[maxm*2],*head[maxn],*ncnt;

void addedge(int u,int v)

{

	ncnt++;

	ncnt->v=v,ncnt->nxt=head[u];

	head[u]=ncnt;

}

void dfs(int u)

{

	vis[u]=true;

	for(node *p=head[u];p;p=p->nxt)

	{

		int v=p->v;

		if(!vis[v]) { val[v]=val[u]^1; dfs(v); }

		else if(val[u]==val[v]) f=true;

	}

}

int main()

{

	ncnt=&edge[0];

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++) 

	{

		int u,v;

		scanf("%d%d",&u,&v);

		addedge(u,v); addedge(v,u);

	}

	for(int i=1;i<=n;i++)

	{

		if(!head[i]) ia++;

		else if(!vis[i])

		{

			f=false;

			dfs(i);

			if(f) pa++;

			else qa++;

		}

	}

	printf("%lld\n",1ll*ia*ia+2ll*ia*(n-ia)+1ll*pa*pa+2ll*qa*qa+2ll*pa*qa);

}
// Slower C++ solution:
#include<cstdio>

#include<vector>

#include<algorithm>

using namespace std;

const int MAXN=100005;



int n,m;

vector<int> adj[MAXN];

int col[MAXN];



bool dfs(int u,int color)

{

	if(col[u])

		return color==col[u];

	col[u]=color;

	bool ret=true;

	for(int i=0;i<(int)adj[u].size();i++)

	{

		int v=adj[u][i];

		if(!dfs(v,color==1?2:1))

			ret=false;

	}

	return ret;

}



int main()

{

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++)

	{

		int u,v;

		scanf("%d%d",&u,&v);

		adj[u].push_back(v);

		adj[v].push_back(u);

	}

	int a=0,b=0,c=0;

	for(int i=1;i<=n;i++)

		if(!col[i])

		{

			if(adj[i].size()==0U)

				c++,col[i]=1;

			else

			{

				if(dfs(i,1))

					a++;

				else

					b++;

			}

		}

	long long ans=1LL*c*c+2LL*c*(n-c)+2LL*a*a+2LL*a*b+1LL*b*b;

	printf("%lld\n",ans);



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 17.928987476748333x):
#include<cstdio>

#define maxn 100005

#define maxm 200005

int n,m,ia,pa,qa;

bool f,val[maxn],vis[maxn];

struct node { int v; node *nxt; } edge[maxm*2],*head[maxn],*ncnt;

void addedge(int u,int v)

{

	ncnt++;

	ncnt->v=v,ncnt->nxt=head[u];

	head[u]=ncnt;

}

void dfs(int u)

{

	vis[u]=true;

	for(node *p=head[u];p;p=p->nxt)

	{

		int v=p->v;

		if(!vis[v]) { val[v]=val[u]^1; dfs(v); }

		else if(val[u]==val[v]) f=true;

	}

}

int main()

{

	ncnt=&edge[0];

	scanf("%d%d",&n,&m);

	for(int i=1;i<=m;i++) 

	{

		int u,v;

		scanf("%d%d",&u,&v);

		addedge(u,v); addedge(v,u);

	}

	for(int i=1;i<=n;i++)

	{

		if(!head[i]) ia++;

		else if(!vis[i])

		{

			f=false;

			dfs(i);

			if(f) pa++;

			else qa++;

		}

	}

	printf("%lld\n",1ll*ia*ia+2ll*ia*(n-ia)+1ll*pa*pa+2ll*qa*qa+2ll*pa*qa);

}