Complementary Graph
Practice
5 (1 votes)
Algorithms
Graphs
Depth first search
Data structures
Problem
58% Success 198 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an undirected graph A, which has n vertices and m edges.
There is another undirected graph B, which has n vertices and n * (n - 1) / 2 - m edges. For each pair of vertices u, v there is an edge between them if and only if they are not connected by an edge in graph A.
Find the number of connected components in graph B and the size of each component.
Input Format:
- The first line contains T, the number of test cases. The following lines contain the descriptions of the test cases.
- The first line of each test case contains two integers, n and m.
- Then m lines follow, each line containing two integers u and v (1 <= u, v <= n) denoting the edges present in graph A.
Output Format:
- On the first line print an integer K - denoting the count of connected components in the graph.
- In the next line, print K integers denoting the size of K connected components in the graph. The size of components should be printed in increasing order.
Constraints-
- \(1 <= T <= 100\)
- \(1 <= n <= 2 * 10^5\)
- \(0 <= m <= min(n * (n - 1) / 2, 2 * 10 ^ 5)\)
- sum of n and m overall testcases \(<= 2 * 10^5\)
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
AlgorithmsDepth First SearchGraphs
2.Xorrrr
Points:50
6 votes
Tags:
Depth First SearchGraphsAlgorithms
Points:50
4 votes
Tags:
Dynamic ProgrammingAlgorithmsGraphsDepth First Search
Editorial