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 (GCC 5.4.1) (judge verdict: Accepted)

//set many funcs template
//Ver.20180717
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long n,m;
rs gr[524288];
mkj mk[524288];

long long color[524288]={0},flag;

long long rep(long long x,long long bc){
  if(color[x]!=0){
    if(color[x]==bc){flag=0;}
  }
  else{
    color[x]=3-bc;
    long long i;
    for(i=mk[x].st;i<mk[x].st+mk[x].kz;i++){
      rep(gr[i].fi,3-bc);
    }
  }
}

long long jud(long long x){
  if(mk[x].st==-1){return -1;}
  flag=1;
  rep(x,2);
  return flag;
}

long long main(void){
    long long i,j,sg=0,hs=0,nh=0,w;
    long long res;
    scanf("%lld%lld",&n,&m);
    for(i=0;i<m;i++){
      scanf("%lld%lld",&gr[2*i].st,&gr[2*i].fi);
      gr[2*i+1].fi=gr[2*i].st;
      gr[2*i+1].st=gr[2*i].fi;      
    }
    for(i=1;i<=n;i++){
      mk[i].st=-1;
    }
    qsort(gr,2*m,sizeof(gr[0]),sortfnc);
    makemkj(gr,mk,2*m);
    for(i=1;i<=n;i++){
      if(color[i]!=0){continue;}
      w=jud(i);
      if(w==-1){sg++;}
      if(w==0){hs++;}
      if(w==1){nh++;}
    }
    res=(n*n)-((n-sg)*(n-sg));
    w=nh*nh*2;
    w+=(hs*nh*2);
    w+=(hs*hs);
    printf("%lld\n",res+w);
    return 0;
}