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 Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		boolean twoCol;
		int size;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			List<Integer>[] adj = new List[n];
			for (int i = 0; i < n; i++) {
				adj[i] = new ArrayList();
			}
			for (int i = 0; i < m; i++) {
				int a = in.nextInt() - 1;
				int b = in.nextInt() - 1;
				adj[a].add(b);
				adj[b].add(a);
			}
			int[] col = new int[n];
			long numNonTwoCol = 0;
			long numTwoCol = 0;
			long numSizeOne = 0;
			List<Integer> sizes = new ArrayList<>();
			List<Boolean> twoC = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				if (col[i] == 0) {
					twoCol = true;
					size = 0;
					dfs(i, 1, col, adj);
					sizes.add(size);
					twoC.add(twoCol);
					if (size == 1) {
						++numSizeOne;
					} else if (twoCol) {
						++numTwoCol;
					} else {
						++numNonTwoCol;
					}
				}
			}
			long ans = 0;
			for (int i = 0; i < sizes.size(); i++) {
				int size = sizes.get(i);
				boolean tc = twoC.get(i);
				if (size == 1) {
					ans += n;
					continue;
				}
				if (tc) {
					ans += numNonTwoCol + numSizeOne * size + 2 * numTwoCol;
				} else {
					ans += numNonTwoCol + numSizeOne * size + numTwoCol;
				}
			}
			out.println(ans);
		}

		private void dfs(int v, int c, int[] col, List<Integer>[] adj) {
			col[v] = c;
			++size;
			for (int u : adj[v]) {
				if (col[u] == 0) {
					dfs(u, 3 - c, col, adj);
				} else if (col[u] != 3 - c) {
					twoCol = false;
				}
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}