Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional

A connected undirected graph has the vertices B, G, P, R, S and weighted edges (weights in brackets): S–P (19), G–R (10), G–S (14), S–B (3), G–P (5), S–R (10), G–B (6), R–B (5). What is the total weight of a minimum spanning tree?

  1. A. 20
  2. B. 19
  3. C. 49
  4. D. 24

Correct answer: B. 19

Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 19. A heaviest-first spanning tree gives 49, and a shortest-path tree rooted at G gives 24.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic