Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
A directed weighted graph has the arcs u→v (weight): Z→G (12), G→Z (1), G→T (11), G→A (3), G→S (7), T→Z (11), T→M (1), A→Z (13), A→T (11), S→G (11), S→T (3), S→A (9), M→Z (11), M→G (15), M→T (11), M→A (13). 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 Z to M?
- A. 23
- B. 1
- C. 24
- D. 2
Correct answer: B. 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 4, and no free arcs gives 23.
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 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…
- An undirected connected graph on the vertices B, M, Q, R, U has the edges B–U, M–R, Q–R, M–Q, B–R, B–M, Q–U, B–Q. How many spanning trees…
- Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. LUL LRD RUU From a cell you may move to…
- A directed graph has the vertices B, D, E, M, Y and the arcs B→M, B→E, B→D, B→Y, M→B, M→E, M→D, E→B, E→Y, D→B, D→M, D→E, D→Y, Y→M. Count…
- An undirected graph has the vertices C, P, T, X and the edges T–P, C–P, C–X, P–X. In how many ways can each vertex be given one of 3…
- Cities B, C, F, T, U are joined by roads with these travel costs: B–U 20, B–T 13, B–C 7, B–F 17, U–T 4, U–C 9, U–F 2, T–C 11, T–F 6, C–F…