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>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=int_fast64_t;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double EPS=1e-9;
const int MOD=1e9+7;
struct UnionFind{
    vector<int> par,dep;
    UnionFind(int n){
        dep.assign(n,1);
        par.assign(n,0);
        for(int i=0;i<n;i++)par[i]=i;
    }
    int find(int x){
        if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }
    bool unite(int u,int v){
        u=find(u);
        v=find(v);
        if(u==v)return false;
        if(dep[u]>dep[v]){
            par[v]=u;
        }else if(dep[u]<=dep[v]){
            par[u]=v;
            if(dep[u]==dep[v]){
                dep[v]++;
            }
        }
        return true;
    }
};
int main(){
    ll n,m;cin>>n>>m;
    UnionFind uf(n);
    vector<int> f(n);
    for(int i=0;i<m;i++){
        int u,v;cin>>u>>v;--u;--v;
        if(!uf.unite(u,v)){
            f[u]=1;
            f[v]=1;
        }
    }
    vector<P> s(n,P(0,0));
    for(int i=0;i<n;i++){
        s[uf.find(i)].first++;
        s[uf.find(i)].second|=f[i];
    }
    ll ans=n*n;
    ll c1=0,c2=0,s1=0,s2=0;
    for(int i=0;i<n;i++){
        if(s[i].first>=2){
            if(s[i].second){
                ans-=s[i].first*s[i].first-1LL;
                ans-=((s1+s2)*s[i].first-(c1+c2))*2LL;
                s1+=s[i].first;
                c1++;
            }else{
                ans-=s[i].first*s[i].first-2LL;
                ans-=((s1*s[i].first-c1)+(s2*s[i].first-c2*2LL))*2LL;
                s2+=s[i].first;
                c2++;
            }
        }else{

        }
    }
    cout<<ans<<endl;
}