Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 B
A directed weighted graph has the arcs u→v (weight): A→Y (11), A→L (15), W→D (4), W→S (10), Y→A (6), Y→W (3), Y→D (9), L→A (10), L→D (8), L→S (11), S→A (10), S→W (15), S→Y (2), S→D (9). 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 A to S?
- A. 3
- B. 24
- C. 0
- D. 25
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 24.
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
- Starting from the integer 13, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 2) if n % 3 == 0: f(n - 2) How many times is f called in total…
- An undirected graph on 6 vertices has the edges J–Y, J–K, Y–K, Y–P, K–T, T–P, T–C, P–C. How many simple paths (no repeated vertex) go from…
- A directed acyclic graph has the vertices D, E, L, M, N, X, Z and the edges L→X, L→N, L→M, D→L, M→N, M→E, Z→E. A topological order lists…
- A tree has vertices C, I, M, R, S, U, X and weighted edges (weights in brackets): M–C (9), C–U (2), C–I (8), C–X (1), M–R (8), U–S (7)…
- 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)…