You are given a directed graph in which each node has an associated price which is a positive integer. Define the array cost as follows: for each
= price of the cheapest node reachable from (including itself).
For instance, in the graph below (with prices shown for each vertex), the cost values of the nodes 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.
(b) Extend this to a linear-time algorithm that works for all directed graphs.