Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): C→A (8); D→E (2); B→A (9); E→D (1); B→D (1); A→E (1); E→A (9); A→B (6). 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. 4
- B. 16
- C. 118
- D. 34
Correct answer: C. 118
Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 118. The number of unreachable pairs (4) and the count of reachable pairs (16) 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
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (3), B–C (7), B–D (5), B–E (7), B–F (7), C–F (2), D–E (1)…
- Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–C (7), A–D (7), B–C (4), B–F (9), B–G (5), C–F (5), D–F (1), E–F…
- Keys are inserted in the order 12 31 77 11 65 57 into an empty binary search tree. Then the key 12 (which has two children) is deleted by…
- Distinct words ['aa', 'ab', 'bb', 'ca', 'aab'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a…
- Keys are inserted in the order 11 88 20 15 45 into an empty binary search tree. Then the key 20 (which has two children) is deleted by…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(6) and count every invocation of f…