# Help : cycles in directed graph related problem

This was problem A in selsie programming challenge held at toph.

Given a directed graph (possible multiple edges and self loops) , for each node :

1) We must visit at least one other node (if possible)

2) Get back to our initial node after visiting (if possible)

3) Our answer is the minimum number of nodes from which we can visit some other node but cannot get back to the initial node.

Number of nodes <= 100000, Number of edges <= 200000.

My thought was if we can start from some node A, visit some other node B, and then come back to A, that means they are in a circle (just ignore self loops). So every node within a cycle is a good node. For every other node if there is no outgoing edge that is also a good node (we only care about whether we could get back). But for others it is possible to visit at least one other node, so we must visit at least one of them but we cannot get back to initial node from any of the visited nodes. But detecting whole cycles in a directed graph will definitely give TLE. I think there is some graph algo which might be helpful, such as concepts like SCC.