Help in codeforces problem !!

I have been trying to find the testcases for which my code fails.

Question-> http://codeforces.com/contest/999/problem/E

and my Solution-> http://codeforces.com/contest/999/submission/39536044

I have really tried many testcases. Plzz see if you can help in finding the testcases or some fault in my logic!!

Are you using dsu? I don’t understand C++ much.

link text

According to this guy dsu can work but when we are doing union we need a dfs too.

i made edges from source to vertices with indegree 0.
After that i used dfs to find all possible vertices where we can reach from source.

Now if some vertices are still left, it means they are involved in a cycle and so no vertex has indegree 0.

So now i used union find to find if there is an edge from some component to the root of some other component. If such an edge exists then we do not have to include that component.