Data Structures & AlgorithmsHardGATE CS · ICPC regional
Directed weighted graph on vertices A, B, C, D with edges (u→v, w): D→A (8); C→B (4); B→A (6); B→D (4); D→B (7). Let d(x, y) be the shortest-path distance from x to y, and consider every ORDERED pair (x, y) with x ≠ y for which y is reachable from x. What is the sum of d(x, y) over those pairs?
- A. 12
- B. 5
- C. 47
- D. 7
Correct answer: C. 47
Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 47. The number of unreachable pairs (5) and the count of reachable pairs (7) are the wrong quantities.
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
- Array [7, 21, 6, 3, 10, 17, 8] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element…
- Coins of denominations [7, 6, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 18? (Coins…
- 4 × 4 grid, rows top to bottom ('#' = blocked, '.' = open): .... / ..#. / ..#. / ..... Count the paths from top-left to bottom-right that…
- Words ['bcb', 'c', 'ac', 'abbb', 'c', 'bac', 'bbb'] are inserted in this order into an empty trie with one node per character, shared…
- Array A = [3, 11, 10, 2, 3, 8, 6]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (9), A–C (8), A–D (9), A–E (19), B–D (3), B–E (8), B–F…