Data Structures & AlgorithmsModerateCodeforces Div 2 D · ICPC regional
A tree has the vertices B, C, F, K, M, N, Q, R, X, Z and the edges C–X, X–Z, X–M, M–K, C–B, Z–R, B–Q, M–N, N–F. What is the minimum number of vertices needed so that every edge has at least one endpoint in the chosen set?
- A. 4
- B. 5
- C. 7
- D. 6
Correct answer: B. 5
Minimum vertex cover on a tree is computed by a DP over children (taking the parent or all children). It is 5 here. Repeatedly picking the highest-degree vertex gives 5, and the number of non-leaf vertices gives 6.
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 tree has vertices with values in brackets: M[0], R[5], A[9], G[-4], H[9]. The edges are M–R, M–A, R–G, M–H. A path is any sequence of…
- Bellman–Ford is run from source P on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: Z→S…
- A directed graph has the vertices F, J, N, P, R, Z and the arcs P→F, P→Z, P→N, J→N, R→P, F→P, F→R, Z→P, Z→N, N→F, N→Z. How many strongly…
- Grid with 4 rows and 4 columns (top to bottom). A cell marked G is a gate; '.' is a normal cell: ...G .GGG GG.G G... Each step, which is a…
- 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…
- 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…