Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional
A tree has the vertices B, E, H, I, Q, R, U, V and the edges V–I, I–H, H–R, H–U, R–B, I–E, U–Q. A centroid is a vertex whose removal leaves no connected component with more than n/2 vertices. Which vertex is the centroid?
- A. B
- B. U
- C. Q
- D. H
Correct answer: D. H
Removing H leaves components of at most 3 vertices, while every other vertex leaves a component bigger than n/2. The highest-degree vertex I is a common wrong guess.
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 on the vertices B, C, D, H, J, T, Z has the arcs T→B, Z→T, B→C, B→D, J→D, J→H (each undirected edge is directed as shown). You may…
- A grid has 4 rows and 4 columns with these values (top to bottom): 9446 8699 5398 3165 A path moves between side-adjacent cells (up, down…
- Floyd–Warshall runs on vertices 1 to 5 with these arcs u→v (weight): 1→2 (4), 1→3 (2), 2→1 (11), 3→1 (8), 3→2 (4), 3→4 (7), 3→5 (4), 4→1…
- Bellman–Ford is run from source U on the directed graph whose arcs (weights in brackets) are listed in the order they are relaxed: K→U…
- A four-wheel combination lock shows four digits 0–9 on wheels that wrap around (9 goes to 0 and 0 goes to 9). One move turns one wheel by…
- A tree has vertices with weights in brackets: D[15], C[15], R[7], L[9], S[1], Z[3], B[13], H[13], F[6]. The edges are D–C, D–R, R–L, D–S…