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 Python (3.4.3) (judge verdict: Accepted)

import sys
input = sys.stdin.readline

N,M = map(int,input().split())
UV = [[int(x) for x in row.split()] for row in sys.stdin.readlines()]

graph = [[] for _ in range(N+1)]
for u,v in UV:
    graph[u].append(v)
    graph[v].append(u)

color = [None] * (N+1)

def calc_comp_data(v):
    c = 0
    q = [v]
    color[v] = 0
    is_bipartite = True
    size = 1
    while q:
        qq = []
        c ^= 1
        for x in q:
            for y in graph[x]:
                if color[y] is None:
                    color[y] = c
                    qq.append(y)
                    size += 1
                elif color[y] == c:
                    continue
                else:
                    is_bipartite = False
        q = qq
    return size,is_bipartite

size = []
is_bipartite = []
for v in range(1,N+1):
    if color[v] is not None:
        continue
    x,y = calc_comp_data(v)
    size.append(x)
    is_bipartite.append(y)

size,is_bipartite

n_point = sum(1 if s == 1 else 0 for s in size)
n_component = len(size)
n_bipartitle = sum(1 if s >= 2 and bl else 0 for s,bl in zip(size,is_bipartite))

answer = 0
for s,bl in zip(size,is_bipartite):
    if s == 1:
        # 第1成分が1点のとき
        answer += N
    elif not bl:
        # 第1成分が2点以上、非二部グラフ
        # 成分の個数が足される
        answer += (n_component - n_point) + s*n_point
    else:
        # 第1成分が2点以上の二部グラフ
        # 相手が2点以上の二部グラフなら、2つできる
        answer += (n_component - n_point) + n_bipartitle + s*n_point

print(answer)