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.)
- A. 3
- B. 20
- C. 17
- 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.
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
- A pile holds p stones. In one move a player removes exactly s stones, where s is one of {4, 5, 6} and s ≤ the pile size. The player who…
- A directed graph has the vertices E, H, L, M, Q, U and the arcs H→U, M→Q, U→H, U→Q, E→H, E→M, L→H. How many strongly connected components…
- A directed graph has the vertices C, I, L, R, U and the arcs I→U, I→C, I→L, R→I, R→U, R→C, R→L, U→C, C→I, C→L, L→U. Count the directed…
- Grid with 3 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: .G.G G.G. .... Each step, which is a move…
- Starting from the integer 6, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- A connected undirected graph has the vertices D, L, Q, R, T, Y and the edges Y–D, Y–T, D–Q, D–R, D–L, R–T, R–L, T–L. Parallel edges are…