Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): E→C (9); C→D (5); C→E (4); A→C (5); B→E (1); C→A (3); E→A (2); B→C (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. 7
- B. 13
- C. 53
- D. 80
Correct answer: D. 80
Floyd–Warshall gives the reachable ordered pairs, and their distances add up to 80. The number of unreachable pairs (7) and the count of reachable pairs (13) 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
- Keys [43, 27, 29, 8, 44, 17, 18, 5, 4] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…
- Directed weighted graph on vertices F, E, D, A, B (source F, target B) with edges: F→E (4); F→D (6); D→E (-3); E→B (1); D→B (6); F→B (11)…
- Directed weighted graph on vertices A, B, C, D with edges B→A (1); B→C (5); C→D (-1); B→D (-1); C→A (-1); D→C (-2); A→D (4). Source A. Run…
- Words ['aad', 'cda', 'bb', 'aaa', 'cbc', 'cdb'] (each may be used at most once). A chain is a sequence of these words in which the first…
- Words ['aa', 'acb', 'caa', 'caa', 'cbba', 'c'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (3), A–D (3), B–D (3), C–E (3), D–E (2). An edge is CRITICAL…