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 <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    vector<int> depth(N, -1);
    function<pair<int, int>(int, int, int)> dfs = [&](int v, int p, int d) {
      depth[v] = d;
      int cnt = 1;
      bool oddloop = false;
      for (int u : G[v]) {
        if (u == p) continue;
        if (depth[u] != -1) {
          oddloop |= (d - depth[u]) % 2 == 0;
        } else {
          auto ch = dfs(u, v, d + 1);
          cnt += ch.first;
          oddloop |= ch.second;
        }
      }
      return make_pair(cnt, oddloop);
    };
    ll sum = 0, oddloop = 0, trivial = 0;
    for (int i = 0; i < N; i++) {
      if (depth[i] != -1) continue;
      auto res = dfs(i, -1, 0);
      if (res.first == 1) continue;
      sum += res.first;
      if (res.second) {
        ++oddloop;
      } else {
        ++trivial;
      }
    }
    ll res = 1ll * N * N - sum * sum;
    res += 2 * (oddloop + trivial) * (oddloop + trivial) -
           2 * oddloop * (oddloop + trivial) + oddloop * oddloop;
    cout << res << endl;
  }
  return 0;
}