Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (12), 1→4 (1), 1→5 (8), 2→1 (10), 2→3 (2), 2→4 (7), 3→1 (1), 3→5 (6), 4→1 (5), 4→2 (12), 4→5 (9), 5→1 (4), 5→2 (1), 5→3 (10). dist[i][i] = 0, dist[i][j] is the arc weight, or ∞ when there is no arc. The outer loop runs over k = 1, 2, … in that order. After the iterations for k = 1 through 2 have finished, what is dist[3][2]?
- A. 13
- B. 7
- C. 15
- D. 14
Correct answer: A. 13
Only intermediate vertices 1 to 2 are allowed in the middle of paths at this point, which gives 13. Stopping one iteration earlier gives 13, and the final distance is 7.
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
- An undirected connected graph on the vertices D, L, R, T, V has the edges D–V, L–R, D–T, V–R, L–T, L–V, V–T, L–D. How many spanning trees…
- Each cell of a grid with 4 rows and 5 columns has an arrow: R = right, L = left, U = up, D = down. RUUUD RLDUL UDLDR RDDRU From a cell you…
- Starting from the integer 9, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- Two unmarked jugs hold 7 litres and 8 litres. Allowed operations: fill a jug completely, empty a jug completely, or pour one jug into the…
- Cities A, B, N, T, U are joined by roads with these travel costs: A–N 15, A–U 2, A–B 4, A–T 14, N–U 17, N–B 5, N–T 13, U–B 8, U–T 6, B–T…
- An undirected connected graph on the vertices D, U, W, X has the edges U–X, D–W, D–X, W–X, D–U. How many spanning trees does it have? (A…