Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Directed weighted graph on vertices E, C, A, B, D (source E, target D) with edges: E→C (2); E→A (3); A→C (-3); C→D (3); A→D (3); E→D (18); E→B (7). Run Dijkstra from E with a min-heap: a vertex is finalised the first time it is popped, its outgoing edges are relaxed then, and a finalised vertex's distance is never changed afterwards (edges into finalised vertices are ignored). What distance to D does it report?
- A. 3
- B. 18
- C. 6
- D. 5
Correct answer: D. 5
Dijkstra finalises C at distance 2 before the negative edge from A is seen, so it reports 5. The true shortest distance is 3, which goes through the negative edge; clamping negatives to 0 or using their absolute values are other wrong models.
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 trie keeps a counter at each node, and every word of the list W = ['acb', 'c', 'bcb', 'c', 'bc', 'a', 'aac'] is inserted once per…
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (3, 5) and must reach (5, 0) (as (row, column)). A knight…
- Dictionary D = {bem, cle, gcc, icd, imb, lbg, lcp, lri, ois, opg, scc, scp} (all words have 3 letters). Starting from the word 'lcd', a…
- Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); A→D (-4); A→B (-2); D→B (0); B→C (-2); A→E (-1); E→D (0); B→E (-4)…
- Array A = [5, 6, 5, 4, 3, 8, 4, 6] (indices 0 to 7). Count the non-empty subsets of positions (each position used at most once, subsets…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 4 / 1 5 3. Goal board: 1 2 3 / 4 5 . A move slides a…