Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
An undirected connected graph on the vertices B, N, S, V, Z has the edges B–Z, S–Z, S–N, B–V, Z–N, B–N, B–S, Z–V. 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. 41
- C. 40
- D. 16
Correct answer: C. 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
- An undirected graph has the vertices A, B, E, F, G, I, J, L, N, R and the edges G–J, G–B, G–R, J–F, J–R, F–L, F–B, F–N, F–E, L–N, L–R…
- A tree has the vertices A, C, F, N, O, S, W, Y, Z and the edges A–C, C–O, A–S, A–Z, O–N, A–F, C–Y, C–W. A centroid is a vertex whose…
- An undirected graph has the vertices J, N, T, U, Z and the edges Z–N, J–U, Z–U, Z–J, T–J, J–N, T–U, T–Z, N–U, T–N. What is the minimum…
- A directed weighted graph has the arcs u→v (weight): A→Y (11), A→L (15), W→D (4), W→S (10), Y→A (6), Y→W (3), Y→D (9), L→A (10), L→D (8)…
- Starting from the integer 13, one operation either adds 1, subtracts 1, or doubles the current value. Values may be any non-negative…
- Consider this recursive function: python def f(n): if n <= 1: return f(n - 2) if n % 3 == 0: f(n - 2) How many times is f called in total…