Problem:
Score : 500 points

Problem Statement

Rng has a connected undirected graph with N vertices.
Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i.

Rng will add new edges to the graph by repeating the following operation:

Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v.

Find the maximum possible number of edges that can be added.

Constraints

2 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq A_i,B_i \leq N

The graph has no self-loops or multiple edges.

The graph is connected.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
A_2 B_2
:
A_M B_M

Output

Find the maximum possible number of edges that can be added.

Sample Input 1

6 5
1 2
2 3
3 4
4 5
5 6

Sample Output 1

4

If we add edges as shown below, four edges can be added, and no more.

Sample Input 2

5 5
1 2
2 3
3 1
5 4
5 1

Sample Output 2

5

Five edges can be added, for example, as follows:

Add an edge connecting Vertex 5 and Vertex 3.

Add an edge connecting Vertex 5 and Vertex 2.

Add an edge connecting Vertex 4 and Vertex 1.

Add an edge connecting Vertex 4 and Vertex 2.

Add an edge connecting Vertex 4 and Vertex 3.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

struct AdjacentMatrix {
    mat: Vec<Vec<usize>>,
}

impl AdjacentMatrix {
    pub fn new(n: usize) -> AdjacentMatrix {
        AdjacentMatrix {
            mat: vec![vec![]; n],
        }
    }

    pub fn connect(&mut self, x: usize, y: usize) {
        self.mat[x].push(y);
        self.mat[y].push(x);
    }
}

struct Solver {
    adj_mat: AdjacentMatrix,
    colors: Vec<i32>,
}

impl Solver {
    fn solve(&mut self, idx: usize, color: i32) -> bool {
        if self.colors[idx] != 0 && self.colors[idx] != color {
            return false;
        }
        self.colors[idx] = color;
        let adjacents = self.adj_mat.mat[idx].iter().cloned().collect::<Vec<_>>();
        for i in adjacents {
            if self.colors[i] == 0 {
                let result = self.solve(i, color * -1);
                if !result {
                    return false;
                }
            } else if self.colors[i] == color {
                self.colors[i] = 2;
                return false;
            }
        }
        true
    }
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut pairs = vec![];
    for _ in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        pairs.push((a, b));
    }
    let mut adj_mat = AdjacentMatrix::new(n);
    for &pair in pairs.iter() {
        adj_mat.connect(pair.0, pair.1);
    }
    let colors = vec![0; n];
    let mut solver = Solver {
        adj_mat: adj_mat,
        colors: colors,
    };
    if solver.solve(0, 1) {
        let mut even_count = 0i64;
        for i in 0..n {
            if solver.colors[i] == 1 {
                even_count += 1;
            }
        }
        let odd_count = n as i64 - even_count;
        println!("{:?}", odd_count * even_count - m as i64);
    } else {
        println!("{:?}", n as i64 * (n as i64 - 1) / 2 - m as i64);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}