Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
A directed weighted graph has the arcs u→v (weight): F→K (4), F→U (1), F→H (13), K→F (12), U→F (13), U→K (4), U→L (8), L→F (2), L→K (2), L→U (2), L→H (1), H→K (14), H→L (4). 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 F to H?
- A. 10
- B. 11
- C. 0
- D. 1
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 1, and no free arcs gives 10.
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 connected undirected graph has the vertices C, K, L, P, U, X, Y and the edges L–X, X–C, X–Y, C–K, C–P, C–U, K–Y, K–P, Y–U, P–U. Parallel…
- A directed acyclic graph has the vertices C, J, P, U, X and the arcs P→C, P→X, U→C, J→C, C→X. Two players alternately move a single token…
- A grid has 3 rows and 4 columns with these values (top to bottom): 1832 3673 2187 A path moves between side-adjacent cells (up, down, left…
- A tree on the vertices J, L, M, N, T has the arcs T→J, J→N, L→T, M→T (each undirected edge is directed as shown). You may reverse the…
- A grid has 5 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): ..#..... ....#..# ...#...# #.#..... ......#…
- An undirected graph on 5 vertices has the edges T–X, X–L, X–B, L–B, L–N, B–N. How many simple paths (no repeated vertex) go from T to N?…