Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional
Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); D→C (-2); D→E (-2); C→B (2); A→D (-2); C→A (2); B→E (-1). Source A. Run Bellman–Ford for exactly n−1 = 4 passes (each pass tries every edge once). Then, using the distances after those passes and no further updates, how many edges (u→v, w) still satisfy dist[u] + w < dist[v] (with dist[u] finite)?
- A. 7
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
After n−1 passes 3 edges still improve, which means a negative cycle is reachable from the source. Checking one pass early, or counting only negative edges, gives different numbers.
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
- Directed weighted graph on vertices C, F, E, D, A (source C, target A) with edges: C→F (5); C→E (7); E→F (-4); F→A (1); E→A (1); C→A (7)…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 2 5 / 1 3 4. Goal board: 1 2 3 / 4 5 . A move slides a…
- Array [10, 28, 18, 27, 13, 14] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Array A = [3, 31, 23, 2, 8, 19, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Distinct keys [5, 4, 7, 27, 25] are inserted, in the order given by the sequence [25, 5, 4, 27, 7], into an empty binary search tree. How…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(7) and count every invocation of f…