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>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define MP make_pair
#define PB push_back
#define LL long long
#define pii pair<int,int>

#define F first
#define S second
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
//const int inf = 0x7fffffff; //beware overflow
//const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
inline LL getint(){
   LL _x=0,_tmp=1; char _tc=getchar();
   while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
   if( _tc == '-' ) _tc=getchar() , _tmp = -1;
   while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
   return _x*_tmp;
}
#define maxn 100005
vector<int> G[maxn];
bool vis[maxn];
int sz;
int dfs(int u, int p=-1, int pattern=0) {

    assert( !vis[u]);
    sz++;
    vis[u] = true;
    int res=0;
    for(int v : G[u]) if(v!=p) {
        if(vis[v]) res = max(res, pattern^1);
        else res = max( res, dfs(v, u, pattern^1) );
    }
    return res;
}
int main() {
    int n=getint(), m=getint();
    for(int i=0;i<m;i++) {
        int x, y; scanf("%d %d", &x, &y);
        x--, y--;
        G[x].PB(y), G[y].PB(x);
    }
    vector<int> v;
    vector<bool> cy;
    LL cnt1=0;
    for(int i=0;i<n;i++)if(!vis[i]) {
        sz=0;
        int tmp=dfs(i);
        if( sz==1 ) cnt1++;
        else v.PB(tmp);
    }

    LL cyc=0, nocyc=0;
    for(int i=0;i<SZ(v);i++) {
        if(v[i]) cyc++;
        else nocyc++;
    }
   //cout << cyc << nocyc << endl;

    LL cnt=cyc+nocyc;
    LL ans = 0;

    while(cnt1){
      ans += 2*n - 1;
      n--; cnt1--;
    }
    //LL ans = cyc+2*nocyc+( nocyc*(nocyc-1) + cnt*(cnt-1) ) + cnt1*cnt1+2*cc*cnt1;
    //ans+=cnt1*cnt1+2*cc*cnt1+ cyc*cyc+nocyc*nocyc*2+cyc*nocyc*2;
    ans+=cyc*cyc+nocyc*nocyc*2+cyc*nocyc*2;
    cout << ans << endl;
}