All Tracks Algorithms Graphs Depth First Search Problem

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++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

HackerEarth Collegiate Cup - Mirror Round

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications