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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long iso0 = 0;
		long iso = 0;
		for(int i=0;i<N;i++) if(E[i].Count == 0) iso0++;
		iso = iso0 * N * 2 - (iso0 * iso0);
		long bi = 0;
		long nbi = 0;
		
		int[] used = new int[N];
		for(int i=0;i<N;i++){
			if(used[i] != 0) continue;
			used[i] = 1;
			Queue<int> Q = new Queue<int>();
			Q.Enqueue(i);
			bool chk = true;
			while(Q.Count>0){
				var now = Q.Dequeue();
				foreach(var nxt in E[now]){
					if(used[nxt] == 0){
						used[nxt] = 3 - used[now];
						Q.Enqueue(nxt);
					} else {
						if(used[nxt] == 3 - used[now]) continue;
						chk = false;
					}
				}
			}
			if(chk){
				bi++;
			}else{
				nbi++;
			}
			//Console.WriteLine(String.Join(" ",used));
		}
		//Console.WriteLine("{0} {1}",bi,nbi);
		
		bi -= iso0;
		long bb = 2 * bi * bi;
		long bn = bi * nbi;
		long nb = nbi * bi;
		long nn = nbi * nbi;
		Console.WriteLine(iso + bb + bn + nb + nn);
		
	}
	int N,M;
	List<int>[] E;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		E = new List<int>[N];
		for(int i=0;i<N;i++) E[i] = new List<int>();
		for(int i=0;i<M;i++){
			d = ria();
			E[d[0]-1].Add(d[1]-1);
			E[d[1]-1].Add(d[0]-1);
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}