We apply DFS on the graph and keep track of two properties for each node in DFS tree produced :1. Its time(or order) of first being discovered in DFS.(say p1)2. The order of oldest ancestor it can reach.(say p2)Initially both are same for every node.
circuit directed graph graph theory algorithm Robert Tarjan