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 Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn check(v: usize, c: bool, edges: &[Vec<usize>], col: &mut [bool],
         vis: &mut [bool], conn: &mut Vec<usize>) -> bool {
    if vis[v] {
        return c == col[v];
    }
    vis[v] = true;
    col[v] = c;
    conn.push(v);
    let mut bip = true;
    for &w in edges[v].iter() {
        bip &= check(w, !c, edges, col, vis, conn);
    }
    bip
}


fn bipartite(edges: &[Vec<usize>]) -> (usize, usize, usize) {
    let n = edges.len();
    let mut col = vec![false; n];
    let mut vis = vec![false; n];
    let mut bip = 0;
    let mut odd = 0;
    let mut single = 0;
    for i in 0 .. n {
        if vis[i] { continue; }
        let mut conn = Vec::new();
        let is_b = check(i, false, edges, &mut col, &mut vis, &mut conn);
        if !is_b || conn.len() == 1 {
            if conn.len() == 1 {
                single += 1;
            } else {
                odd += 1;
            }
        } else {
            bip += 1;
        }
    }
    (bip, odd, single)
}

fn solve() {
    let n = get();
    let m = get();
    let mut edges = vec![Vec::new(); n];
    for _ in 0 .. m {
        let u = get::<usize>() - 1;
        let v = get::<usize>() - 1;
        edges[u].push(v);
        edges[v].push(u);
    }
    let (bip, odd, single) = bipartite(&edges);
    let bip = bip as i64;
    let odd = odd as i64;
    let single = single as i64;
    let n = n as i64;
    println!("{}", 2 * bip * (bip + odd) + odd * odd
             + n * n - (n - single) * (n - single));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}