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<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
  int n,m;cin>>n>>m;
  vector<int> v[n+1];
  int a[m],b[m];
  map<pii,int> mp;
  rep(i,0,m){
    cin>>a[i]>>b[i];
    v[a[i]].push_back(b[i]);
    v[b[i]].push_back(a[i]);
    mp[{a[i],b[i]}]=i;
    mp[{b[i],a[i]}]=i;
  }
  bool used[n+1],usedm[m];
  fill(used,used+n+1,false);
  fill(usedm,usedm+m,false);
  ll num[3];
  fill(num,num+3,0);
  rep(i,1,n+1){
    if(used[i])continue;
    int cnt=0,cntm=0;
    queue<int> q;q.push(i);
    used[i]=true;
    while(q.size()>0){
      int now=q.front();q.pop();
      cnt++;
      rep(j,0,v[now].size()){
        int ne=v[now][j];
        int numm=mp[{now,ne}];
        if(usedm[numm]==false)cntm++;
        usedm[numm]=true;
        if(used[ne])continue;
        q.push(ne);
        used[ne]=true;
      }
    }
    if(cntm==0)num[0]++;
    else if(cntm==cnt-1)num[2]++;
    else num[1]++;
  }
  ll ans=2*num[2]*num[2];
  ans+=num[1]*num[1]+2*num[1]*num[2];
  ans+=2*n*num[0]-num[0]*num[0];
  cout<<ans<<endl;
}