Bipartite

Time limit: 1.2s Memory limit: 256MB Input: Output:

You are given an undirected graph GG with NN vertices and MM edges. The edges are numbered from 00 to M1M − 1, and edge ii (0i<M0 \leq i \lt M) connects vertices aia_i and bib_i. The graph does not contain self-loops, i.e., aibia_i \neq b_i for all ii.

A partial graph GG' of GG is a graph obtained by selecting a subset of the edges of GG. In particular, for any 0lr<M0 \leq l \leq r \lt M, we define PG(l,r)PG(l, r) as the partial graph containing all edges with indices between ll and rr, inclusive.

A graph is called bipartite if its vertex set can be partitioned into two subsets AA and BB such that there are no edges between any two vertices within the same subset.

Your task is to count the number of bipartite partial graphs of the form PG(l,r)PG(l, r). Formally, compute

l=0M1r=lM1F(l,r),\sum_{l=0}^{M-1} \sum_{r=l}^{M-1} F(l, r),

where F(l,r)=1F(l, r) = 1 if PG(l,r)PG(l, r) is bipartite, and F(l,r)=0F(l, r) = 0 otherwise.

Input data

The input consists of:

  • One line containing two integers NN and MM – the number of vertices and the number of edges, respectively.
  • MM subsequent lines, where the ii-th line contains two integers aia_i and bib_i, describing edge ii.

Output data

The output file must contain a single line consisting of 64-bit integer, the number of bipartite PG(l,r)PG(l, r) graphs.

Constraints and clarifications

  • 1N200 0001 \leq N \leq 200\ 000.
  • 1M400 0001 \leq M \leq 400\ 000.
  • 1ai,biN1 \leq a_i, b_i \leq N, and aibia_i \neq b_i for each ii such that 0i<M0 \leq i \lt M.
# Score Constraints
1 0 Examples.
2 10 N,M50N, M \leq 50.
3 7 N,M200N, M \leq 200.
4 10 N,M1000N, M \leq 1000.
5 20 N,M30 000N, M \leq 30\ 000.
6 14 N,M60 000N, M \leq 60\ 000.
7 20 N,M100 000N, M \leq 100\ 000.
8 19 No additional constraints.

Example 1

stdin

3 3
1 2
1 3
2 3

stdout

5

Explanation

In the first sample case graph GG is displayed in the following figure.

The bipartite PG(l,r)PG(l, r) graphs are PG(0,0)PG(0, 0), PG(0,1)PG(0, 1), PG(1,1)PG(1, 1), PG(1,2)PG(1, 2), PG(2,2)PG(2, 2). Note that PG(0,2)PG(0, 2) is not bipartite.

Example 2

stdin

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

stdout

21

Explanation

In the second sample case we have the following graph GG.

The bipartite PG(l,r)PG(l, r) graphs are PG(0,0)PG(0, 0), PG(0,1)PG(0, 1), PG(1,1)PG(1, 1), PG(0,2)PG(0, 2), PG(1,2)PG(1, 2), PG(2,2)PG(2, 2), PG(0,3)PG(0, 3), PG(1,3)PG(1, 3), PG(2,3)PG(2, 3), PG(3,3)PG(3, 3), PG(3,4)PG(3, 4), PG(4,4)PG(4, 4), PG(3,5)PG(3, 5), PG(4,5)PG(4, 5), PG(5,5)PG(5, 5), PG(3,6)PG(3, 6), PG(4,6)PG(4, 6), PG(5,6)PG(5, 6), PG(6,6)PG(6, 6), PG(6,7)PG(6, 7), PG(7,7)PG(7, 7). A few examples of invalid partial graphs are PG(0,4)PG(0, 4), PG(1,5)PG(1, 5), PG(0,7)PG(0, 7), and PG(5,7)PG(5, 7).

Log in or sign up to be able to send submissions!