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# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N;
    private int M;
    private List<int>[] E;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        E = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            E[i] = new List<int>();
        }

        for (int i = 0; i < M; i++)
        {
            int u = sc.NextInt() - 1;
            int v = sc.NextInt() - 1;
            E[u].Add(v);
            E[v].Add(u);
        }

        // 自己辺が無い
        // (a,b)-(a,b'), (a,b)-(a',b)は無い
        // 
        // 辺の個数 2M^2

        // 連結グラフ A,Bがある
        // Cを同じルールで構成するとき、連結成分の個数

        // Aにおいてa-a' Bに b-b'に長さ一致パスがある
        // Cに(a,b)-(a'b')のパスがある

        // 遠回りすると長さ2増やせるのでパリティが一致してれば良い

        // A,B 
        // 片方の頂点1つ辺0個
        // Cに辺作れない 連結成分A,Bの頂点の積

        // 片方が二部グラフじゃない
        // Bが二部グラフじゃないとする
        // Bの奇数長サイクル
        // a'-b'
        // a'->奇数長サイクル->b' 
        // a'-b'のパスは偶奇両方できる
        // 連結成分1個

        // 両方二部グラフ
        // Aのa-b,Bのa'-b'の偶奇が一致してる頂点で連結成分作れる
        // 連結成分2個


        // 頂点数1個連結成分
        long g1 = 0;
        // 二部グラフ連結成分
        long g2 = 0;
        // それ以外連結成分
        long g3 = 0;

        var q = new Queue<int>();
        int[] parity = new int[N];
        for (int i = 0; i < N; i++)
        {
            if (parity[i] != 0) continue;
            parity[i] = 1;
            if (E[i].Count == 0)
            {
                g1++;
                continue;
            }

            // 二部グラフか? 
            bool f2 = true;
            q.Enqueue(i);
            while (q.Count > 0)
            {
                var d = q.Dequeue();
                foreach (int to in E[d])
                {
                    if (parity[to] == 0)
                    {
                        parity[to] = -parity[d];
                        q.Enqueue(to);
                    }
                    else
                    {
                        f2 &= parity[to] == -parity[d];
                    }
                }
            }

            if (f2) g2++;
            else g3++;
        }

        long ans = 0;
        // g1
        ans += g1 * N + (N - g1);
        // g2 
        ans += g2 * g2 * 2;
        // g3 とg2,g3
        ans += g3 * (g2 + g3) + g2 * g3;

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}