Problem:
Score : 800 points

Problem Statement

Takahashi has received an undirected graph with N vertices, numbered 1, 2, ..., N.
The edges in this graph are represented by (u_i, v_i).
There are no self-loops and multiple edges in this graph.

Based on this graph, Takahashi is now constructing a new graph with N^2 vertices, where each vertex is labeled with a pair of integers (a, b) (1 \leq a \leq N, 1 \leq b \leq N).
The edges in this new graph are generated by the following rule:

Span an edge between vertices (a, b) and (a', b') if and only if both of the following two edges exist in the original graph: an edge between vertices a and a', and an edge between vertices b and b'.

How many connected components are there in this new graph?

Constraints

2 \leq N \leq 100,000

0 \leq M \leq 200,000

1 \leq u_i < v_i \leq N

There exists no pair of distinct integers i and j such that u_i = u_j and v_i = v_j.

Input

The input is given from Standard Input in the following format:

N M
u_1 v_1
u_2 v_2
:
u_M v_M

Output

Print the number of the connected components in the graph constructed by Takahashi.

Sample Input 1

3 1
1 2

Sample Output 1

7

The graph constructed by Takahashi is as follows.

Sample Input 2

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

Sample Output 2

18

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
vector<ll> nex[100009],used(100009,0),col(100009,-1);
int main(){
	ll n,m,is=0,nb=0,nnb=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		ll x,y;
		cin>>x>>y;
		nex[x].pb(y);
		nex[y].pb(x);
	}
	for(int i=1;i<=n;i++){
		if(used[i]==0){
			used[i]=1;
			if(nex[i].size()==0){
				is++;
			}
			else{
				queue<ll> que;
				vector<ll> old;
				que.push(i);
				old.pb(i);
				col[i]=0;
				ll fl=0;
				while(!que.empty()){
					ll cur = que.front(); que.pop();
					used[cur]=1;
					for(int j=0;j<nex[cur].size();j++){
						if(used[nex[cur][j]]==0){
							que.push(nex[cur][j]);
							old.pb(nex[cur][j]);
							if(col [ nex[cur][j] ] == -1){
								col [ nex[cur][j] ] = col [cur] +1;
							}
							if( (col[nex[cur][j]]-col[cur])%2!=1){
								if(fl==0){
									fl=1;
									nnb++;
								}
							}
						}
					}
				}
				if(fl==0)nb++;
				for(int i=0;i<old.size();i++){
					used[ old[i] ] =1;
				}
			}
		}
	}
	//cout<<is<<" "<<nb<<" "<<nnb<<endl;
	cout<< 2*n*is - is*is + 2*nb*nb + 2*nb*nnb + nnb*nnb<<endl;
	return 0;
}