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 = 0;
	}
	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++) {
		printf("single = %d, bipartite = %d, other = %d  ", single, bipartite, other);
		int j;
		for (j = 1; j <= N; j++) printf("%2d ", used[j]);
			printf("\n");
		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;

	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 v, int sign) {
	int res = 1;
	list *node;

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

	return res;
}