- Construct component graph.
- Topological sort
- Check whether it has a linear chain, if yes then return “Yes”.
The running time is O(|V|+|E|).
If u and v are in the same component, then there is a path from u to v. If u and v are in different component, since the component graph is a linear chain. There is one path from u to v or v to u.