Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

An undirected connected graph on the vertices F, G, I, Z has the edges Z–G, Z–I, F–Z, F–I, F–G, G–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. 3
  2. B. 20
  3. C. 17
  4. D. 16

Correct answer: D. 16

The Matrix-Tree theorem gives the count as any cofactor of the Laplacian, here 16. Choosing any 3 of the 6 edges gives 20 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