Data Structures & AlgorithmsHardGATE CS · ICPC regional
A directed weighted graph has the arcs u→v (weight): J→Z (11), J→G (6), T→H (1), Z→J (8), Z→S (3), Z→G (3), S→J (2), S→T (12), S→G (2), S→H (2), G→J (15), G→T (13), H→Z (4), H→S (8), H→G (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 J to H?
- A. 1
- B. 16
- C. 17
- D. 2
Correct answer: A. 1
Dijkstra on states (vertex, number of free arcs used) gives 1; 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 16.
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 counter starts at 1. Each step, you may add 1, add 2, or double the counter. Each step must stay at or below 15. Two sequences of steps…
- 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…
- An undirected graph has the vertices D, N, P, W, Z and the edges W–D, W–P, W–Z, D–N, N–Z. In how many ways can each vertex be given one of…
- Consider this function: python def g(n): if n < 3: return n if n % 2 == 0: return g(n - 3) + g(n - 3) return g(n - 3) - 1 What value does…
- A grid has 7 rows and 8 columns (rows listed top to bottom; '.' is an open cell, '#' a wall): .......# ...#.... ..#..... .#.#.##. .#..#…
- 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…