Connected Intervals

5

2 votes
Algorithms, Depth First Search, Graphs, Hard
Problem

Given a graph having N vertices and an array A of M undirected edges, find the number of pairs of indices (l,r),1lrM, in A, such that if we consider edges only from A[l],A[l+1],...,A[r], then the graph is connected.

Input Format:
First line consists of two space separated integers denoting N and M.
Following M lines consists of two space separated u and v, denoting an undirected edge.

Output Format:
Print the required answer.

Constraints:
1N,M105
1u,vN

Sample Input
2 1
2 1
Sample Output
1
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?