Connected Intervals
Practice
5 (2 votes)
Algorithms
Depth first search
Graphs
Hard
Problem
18% Success 205 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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\)
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
AlgorithmsGraphsHard
Points:50
5 votes
Tags:
AlgorithmsApprovedCombinatoricsGraphsHardOpenTrees
Points:50
4 votes
Tags:
Dynamic ProgrammingAlgorithmsGraphsDepth First Search
Editorial
No editorial available for this problem.