Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A connected undirected graph has the vertices A, B, E, J, M and weighted edges (weights in brackets): M–E (8), A–E (17), M–B (10), A–B (13), J–B (11), A–M (5). What is the total weight of a minimum spanning tree?
- A. 51
- B. 37
- C. 34
- D. 35
Correct answer: C. 34
Kruskal's algorithm (take the cheapest edge that does not form a cycle) gives 34. A heaviest-first spanning tree gives 51, and a shortest-path tree rooted at A gives 37.
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 B, D, O, Q, T, X and the edges D–Q, X–D, B–D, X–Q, O–D, X–T, B–Q, D–T, X–O. What is the minimum…
- A directed acyclic graph has the vertices A, E, F, J, L, N and the arcs F→N, F→E, F→J, F→A, L→E, N→E, E→A, J→A. Two players alternately…
- A bipartite graph has left side P1, P2, P3, P4 and right side Q1, Q2, Q3, Q4, Q5, with edges P1–Q1, P4–Q1, P1–Q2, P1–Q5, P4–Q5, P2–Q5…
- A tree has vertices with weights in brackets: Y[6], L[12], B[1], X[10], W[6], I[3], N[4], V[14], J[7]. The edges are Y–L, Y–B, L–X, L–W…
- A directed graph has the vertices D, F, M, O, S and the arcs M→D, M→O, D→O, D→F, O→S, F→O, S→M. Count the directed Hamiltonian paths…
- On an 7×7 chessboard, rows and columns are numbered 0 to 6, and squares are written (row, column). A knight moves in the usual L-shape…