Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional
A connected undirected graph has the vertices B, G, P, R, S and weighted edges (weights in brackets): S–P (19), G–R (10), G–S (14), S–B (3), G–P (5), S–R (10), G–B (6), R–B (5). What is the total weight of a minimum spanning tree?
- A. 20
- B. 19
- C. 49
- D. 24
Correct answer: B. 19
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 19. A heaviest-first spanning tree gives 49, and a shortest-path tree rooted at G gives 24.
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 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…
- 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…