I've been struggling with a question - Not sure if I found the best algorithm possible. Would appreciate your suggestions!
The question: Given directed graph G=(V,E), suppose V={1,2,...,n} (i.e. vertices are numbered between 1 and n).
Let's mark with R(v) the group of vertices that are reachable from the vertex v with a directed path in G.
Let's mark r(v) to be the minimal vertex in R(v). (r(v) vertex has the minimal number in the group R(v)).
Provide algorithm that finds for each vertex v in V(G) the r(v).
What I did is a reduction to an algorithm based on Dijkstra. At first, I turned all the numbered vertices into sets of 2 vertices - so every vertex u would be represented as $u_{in}$ and $u_{out}$ and an edge between $u_{in}$ and $u_{out}$ with a weight that is represented as the number of u.
Meaning, an edge from v to x will now pass from $v_{out}$ to $x_{in}$ and it's weight would be 0. while the edge between $v_{in}$ and $v_{out}$ would weight as the number represented v.
IN THIS WAY, I need to run Dijkstra algorithm n times for |V(G)| vertices - is there a better solution??