Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS
An undirected connected graph on the vertices B, M, Q, R, U has the edges B–U, M–R, Q–R, M–Q, B–R, B–M, Q–U, B–Q. How many spanning trees does it have? (A spanning tree is a set of edges that connects all vertices with no cycle.)
- A. 4
- B. 16
- C. 70
- D. 40
Correct answer: D. 40
The Matrix-Tree theorem gives the count as any cofactor of the Laplacian, here 40. Choosing any 4 of the 8 edges gives 70 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
- Each cell of a grid with 3 rows and 3 columns has an arrow: R = right, L = left, U = up, D = down. LUL LRD RUU From a cell you may move to…
- A directed graph has the vertices B, D, E, M, Y and the arcs B→M, B→E, B→D, B→Y, M→B, M→E, M→D, E→B, E→Y, D→B, D→M, D→E, D→Y, Y→M. Count…
- An undirected graph has the vertices C, P, T, X and the edges T–P, C–P, C–X, P–X. In how many ways can each vertex be given one of 3…
- Cities B, C, F, T, U are joined by roads with these travel costs: B–U 20, B–T 13, B–C 7, B–F 17, U–T 4, U–C 9, U–F 2, T–C 11, T–F 6, C–F…
- A tree has vertices with weights in brackets: E[6], C[8], O[8], B[11], X[14], D[9], T[5], M[1]. The edges are E–C, C–O, E–B, B–X, X–D…
- Bellman–Ford is run from source O on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: L→O…