Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A directed weighted graph has the arcs u→v (weight): Y→K (14), Y→Q (6), K→L (4), K→T (5), L→Q (8), D→Y (3), D→Q (11), D→T (3), Q→Y (12), Q→K (14), Q→L (13), Q→D (4), T→Y (6), T→K (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 Y to T?
- A. 1
- B. 14
- C. 0
- D. 3
Correct answer: C. 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 13.
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
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. UURD DLRU LRUU From a cell you may move…
- A grid has 3 rows and 4 columns with these values (top to bottom): 4179 9341 9892 A path moves between side-adjacent cells (up, down, left…
- Two unmarked jugs hold 4 litres and 5 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- A directed graph has the vertices J, K, L, R, W and the arcs W→K, W→L, W→J, K→W, K→L, K→R, L→W, L→K, L→J, J→L, R→K, R→J. Count the…
- The directed acyclic graph has the vertices C, I, J, R, Y, Z and the arcs C→R, Z→J, R→Y, I→Z, Z→Y, C→Y, Z→C, Y→J, I→C, I→J, Z→R, R→J. How…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…