In the question http://www.spoj.com/problems/BOTTOM/ i am regularly getting a wrong answer.
I am trying to modify Targans Algorithm for Connected Components. This is my code
My logic is to modify Targans algorithm
- Using Targans algorithm. When we start dfs in a TREE. Now whenever there is a pop in the stack (global) in my code it means that these elements constitute a Connected Component but the elements before it in the stack cannot be sink since some of its descendants have already been removed .
- Now before moving to the next tree in the bottom based recursion we clear the whole stack so that it works.
Could anyone please supply me with counter cases or my flaw.
Thanking you in advance .