Connected Intervals
Tag(s):

## Algorithms, DFS, Graph Theory, Hard

Problem
Editorial
Analytics

Given a graph having N vertices and an array A of M undirected edges, find the number of pairs of indices $(l,r), 1 \le l \le r \le M$, 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:
$1 \le N, M \le 10^5$
$1 \le u, v \le N$

SAMPLE INPUT
2 1
2 1

SAMPLE OUTPUT
1

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, Visual Basic

## CODE EDITOR

Initializing Code Editor...
Your Rating:

## This Problem was Asked in

Challenge Name

HackerEarth Collegiate Cup - Mirror Round

OTHER PROBLEMS OF THIS CHALLENGE
• Basic Programming > Bit Manipulation
• Algorithms > Dynamic Programming
• Algorithms > Sorting
• Algorithms > Dynamic Programming
• Algorithms > Graphs
• Data Structures > Advanced Data Structures
• Algorithms > Graphs
• Math > Linear Algebra
• Algorithms > Searching
• Algorithms > Dynamic Programming
Notifications

?