Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
A directed weighted graph has the arcs u→v (weight): Y→N (3), Y→E (9), Y→H (3), N→Y (3), N→E (4), N→H (7), E→N (15), E→A (11), H→Y (2), H→N (6), A→E (12), A→H (15). 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 A?
- A. 19
- B. 1
- C. 0
- D. 18
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 18.
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
- An undirected graph has the vertices D, F, J, L, N, Y and the edges D–Y, Y–N, Y–J, N–F, F–J, J–L. In how many ways can each vertex be…
- A tree on the vertices F, I, P, S, T, W, Z has the arcs W→T, T→Z, W→S, W→F, P→T, P→I (each undirected edge is directed as shown). You may…
- Bellman–Ford is run from source J on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: C→J…
- Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. ULU LUR ULU From a cell you may move to…
- A tree has vertices A, D, E, J, L, Q, T, W, X and weighted edges (weights in brackets): L–T (2), T–D (6), D–W (9), T–Q (6), Q–J (7), L–X…
- Each cell of a grid with 3 rows and 4 columns has an arrow: R = right, L = left, U = up, D = down. DLUL RUUR DLRD From a cell you may move…