Graphs

GRAPH Modelling - Multi-Source BFS --> Use normal BFS but insert all the sources in queue and make their distance = 0 --> Update the distance for others as usual for normal BFS ( Link ) Transform existing Graph and use BFS (non-weighted) & Dijkstra (weighted) Hot (red) - Cold (blue) problem => Update graph s.t. red & blue are alternate make 2*n nodes as A => A' and A'' connect A' -> B'' (for hot) and A'' -> B' (for cold) Directed - weighted G + can remove k edges make G => k+1 times as A', A'', A''', ..... Add edge of weight 0 in between the k+1 graphs n city + m roads + max storage (c litre) => weighted road (consume w litre) + cost[i] (cost per litre to refuel at i-th point) => min. cost from s to t We have to move from A to B capacity = 3. From A -> A' -- 1 litre needed at value in cost array. From A''' -> B' because loss of 2 litres (as shown in the below d...