Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed weighted graph has the arcs u→v (weight): B→U (10), B→S (15), O→U (1), O→S (9), O→P (7), O→L (11), U→O (8), U→S (3), S→L (2), P→O (7), P→U (13), P→S (13), P→L (3), L→B (7), L→O (7), L→S (11), L→P (5). You may choose at most 2 arcs and make each of them cost 0 (the arcs keep their directions). What is the minimum possible cost of a path from B to L?
- A. 0
- B. 16
- C. 15
- D. 2
Correct answer: A. 0
Dijkstra on states (vertex, number of free arcs used) gives 0; the optimum may free arcs that are not on the cheapest path. Freeing the heaviest arc of the shortest path greedily gives 2, and no free arcs gives 15.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A tree has the vertices D, G, I, J, M, T, X, Y and the edges Y–I, I–J, J–G, J–X, G–T, X–M, Y–D. A set D dominates the tree if every vertex…
- An undirected graph has the vertices D, E, H, K, L, Q, V, Z and the edges Q–H, Q–V, Q–K, L–Z, L–D, E–V, E–K, Z–V, Z–K, H–K, V–D. What is…
- Two unmarked jugs hold 7 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {1, 2, 4} and s ≤ the pile size. The player who…
- A tree has the vertices F, G, J, T, U, W, Y and the edges G–T, T–Y, G–U, Y–J, J–W, W–F. What is the minimum number of vertices needed so…
- A directed graph has the vertices A, E, J, M and the arcs M→E, M→J, M→A, E→A, J→M, J→A, A→M, A→E, A→J. Count the directed Hamiltonian…