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: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>

typedef struct Tlist{
	struct Tlist *next;
	int num;
} list;

void make_node(int, int);
int dfs(int, int);

int N, M;
list edge[100010];
int used[100010];

int main(void) {
	int i, tmp[2], single = 0, bipartite = 0, other = 0;
	long long int ans = 0;

	scanf("%d%d", &N, &M);
	// リストの初期化
	for (i = 1; i <= N; i++) {
		edge[i].next = NULL;
		edge[i].num = i;
	}
	for (i = 0; i < M; i++) {
		scanf("%d%d", &tmp[0], &tmp[1]);
		make_node(tmp[0], tmp[1]);
		make_node(tmp[1], tmp[0]);
	}

	for (i = 1; i <= N; i++) {
		if (used[i] != 0) continue;

		if (edge[i].next == NULL)
			single++;
		else if (dfs(i, 1))
			bipartite++;
		else
			other++;
	}

	ans += (long long int)single * (N - single) * 2 + single * single;
	ans += (long long int)other * bipartite * 2 + other * other;
	ans += (long long int)bipartite * bipartite * 2;
	printf("%lld\n", ans);

	return 0;
}

void make_node(int index, int value) {
	list *node = &edge[index];
	while (node->next != NULL) 
		node = node->next;
	node->next = (list *)malloc(sizeof(list));

	node = node->next;
	node->next = NULL;
	node->num = value;
}

// 二部グラフなら1、そうでなければ0を返す
int dfs(int index, int sign) {
	if (used[index] == sign)
		return 1;
	else if (used[index] == -sign)
		return 0;

	int res = 1;
	used[index] = sign;
	list *node = &edge[index];
	// usedを埋めるため途中で再帰を終了しない
	while (node->next != NULL) {
		node = node->next;
		if(!dfs(node->num, -sign)) 
			res = 0;
	}
	return res;
}