Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 B

An undirected connected graph on the vertices D, H, I, K, M has the edges H–K, I–K, D–H, D–M, D–K, D–I, H–M, M–K, H–I. How many spanning trees does it have? (A spanning tree is a set of edges that connects all vertices with no cycle.)

  1. A. 126
  2. B. 76
  3. C. 75
  4. D. 5

Correct answer: C. 75

The Matrix-Tree theorem gives the count as any cofactor of the Laplacian, here 75. Choosing any 4 of the 9 edges gives 126 sets, but most of them contain a cycle or leave a vertex out.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic