CAPCITY - Capital City
There are N cities in Flatland connected with M unidirectional roads. The cities are numbered from 1 to N. The Flat Circle of Flatland (FCF) wants to set up a new capital city for his kingdom. For security reasons, the capital must be reachable from all other cities of Flatland. FCF needs the list of all candidate cities. You are the chief programmer at FACM (Flat Association for Computing Machinery) responsible for providing the list to FCF as soon as possible.
The first line of the input file contains two integers։ 1≤N≤100,000 and 1≤M≤200,000. Each of the following M lines contains two integers 1≤A, B≤N denoting a road from A to B.
The output file contains an integer denoting the number of candidate cities followed by the list of candidate cities in increasing order.
20th test case for me was not printing the cities in increasing order :(
can also be solved using Kosaraju's algo.
TLE even after using TARJAN ! any hint?
nice question based on tarjan's algorithm , keep in mind that you can easily break away when you get 1st scc as it will give the required answer and then sort all the elements of the scc and then print them
AC in one go :))
use condensation of graph
After 3 hours AC in one go
Done with a combination of DSU and DFS
Awesome One!!!!Don't forget to print the cities in increasing order!!!!Similar problem TOUR !!:P
Weak test cases..No test cases for 0 capital city..Last edit: 2018-06-06 08:41:55