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: Wrong Answer)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int N=1e6;
int n,m,vis[N+10],head[N+10],tot;
LL cnt1=0,cnt2=0,cnt3=0;
struct data {
    int next,num;
}edge[N+10];
void Add(int u,int v) {
    edge[++tot].next=head[u];
    edge[tot].num=v;
    head[u]=tot;
}
int dfs(int x,int k) {
    if (vis[x]!=-1&&vis[x]!=k) return 0;
    if (vis[x]!=-1) return 1;
    vis[x]=k;
    for (int i=head[x];i!=-1;i=edge[i].next) {
	int kx=edge[i].num;
	int nowk=dfs(kx,k^1);
	if (nowk==0) return 0;
    }
    return 1;
}
int main() {
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    for (int i=1;i<=m;i++) {
	int u,v;
	scanf("%d%d",&u,&v);
	Add(u,v);
	Add(v,u);
    }
    memset(vis,-1,sizeof(vis));
    for (int i=1;i<=n;i++) {
	if (vis[i]!=-1) continue;
	if (head[i]==-1) {
	    cnt3++;
	    continue;
	}
	int k=dfs(i,1);
	if (k==0) cnt1++;
	else cnt2++;
    }
    LL ans=n*n-(n-cnt3)*(n-cnt3);
    ans+=cnt1*cnt1+cnt1*cnt2*2+cnt2*cnt2*2;
    printf("%lld\n",ans);
    return 0;
}