Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS
A directed weighted graph has the arcs u→v (weight): X→L (9), X→K (15), L→X (11), L→O (3), L→K (1), L→M (15), O→X (11), O→L (5), O→M (7), K→X (12), K→L (14), K→O (14), K→M (14), M→L (13), M→O (7), M→K (12). 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 X to M?
- A. 20
- B. 1
- C. 19
- D. 0
Correct answer: D. 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 3, and no free arcs gives 19.
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
- The directed acyclic graph has the vertices A, Q, T, V, W, Z and the arcs A→T, Z→Q, A→Q, W→T, Q→T, V→T, Z→V, A→V, V→Q. How many distinct…
- Two unmarked jugs hold 3 litres and 7 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A tree on the vertices E, H, N, U, W, Z has the arcs H→N, N→Z, U→N, U→E, W→Z (each undirected edge is directed as shown). You may reverse…
- A directed graph with no directed cycles has arcs u→v (weight) : V→K (4), V→X (3), K→F (-1), K→X (-2), F→X (8), X→W (8). Weights may be…
- A counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 19. Two sequences of steps…
- An undirected graph has the vertices D, M, R, V and the edges M–D, M–V, M–R, D–V, D–R, V–R. A walk may repeat vertices and edges. How many…