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.