Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

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 spanning tree is a set of edges that connects all vertices with no cycle.)

  1. A. 4
  2. B. 10
  3. C. 8
  4. D. 2

Correct answer: C. 8

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