How to check if for every pair of vertices $u,v$ there exists a vertex $w$ that from it there is a path to $u$ and $v$?

169 Views Asked by At

I'm looking to build a linear time algorithm that determines if given a directed graph $G=(V,E)$ , and for every $u,v\in{V}$ there exists $w\in{V}$ where there is a path from $w$ to $u$ and a path from $w$ to $v$.

I thought of running DFS from a random vertex $u$ and then to check if the resulting DFS tree has a vertex $w$ with a back edge to $u$ this way i take care of finding a vertex $w$ that has a path to $u$, and i think this $w$ will also have a path to any descendant of $u$.

Does this algorithm cover all of the cases?