You are given a directed graph in which each node u ∈ V has an associated price pu which is a positive integer. Define the array cost as follows: for each u ∈ V,
cost[u] = price of the cheapest node reachable from u (including u itself).
For instance, in the graph below (with prices shown for each vertex), the cost values of the nodes A, B, C, D, E, F are 2,1,4,1,4, 5, respectively.

Your goal is to design an algorithm that fills in the entire cost array (i.e., for all vertices).
(a) Give a linear-time algorithm that works for directed acyclic graphs. (Hint: Handle the vertices in a particular order.)
(b) Extend this to a linear-time algorithm that works for all directed graphs. (Hint: Recall the “two-tiered” structure of directed graphs.)
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.