I am trying to solve the following problem.
I am using the approach mentioned here to solve this problem https://www.quora.com/How-can-I-find-the-node-in-a-graph-that-is-reachable-from-every-other-node-in-the-graph-How-can-I-count-the-number-of-such-nodes
- Condense the graph after finding the strongly connected components of the graph (I am using Tarjan’s algorithm)
- Find a vertex with out degree 0. If there is only one such vertex, print all the original vertices corresponding to the found vertex. Otherwise print 0.
For some reason I can’t get it to pass the last test case. Can you share pointers as to what could be going wrong?
I have attached my full code below. I gives WA on just the last test case.
The is the ideone link for code.