Data Structures & AlgorithmsModerateCodeforces Div 2 D · ICPC regional
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 removal leaves no connected component with more than n/2 vertices. Which vertex is the centroid?
- A. C
- B. Z
- C. O
- D. N
Correct answer: A. C
Removing C leaves components of at most 4 vertices, while every other vertex leaves a component bigger than n/2. The highest-degree vertex A 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
- 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…
- An undirected graph on 6 vertices has the edges J–Y, J–K, Y–K, Y–P, K–T, T–P, T–C, P–C. How many simple paths (no repeated vertex) go from…
- A directed acyclic graph has the vertices D, E, L, M, N, X, Z and the edges L→X, L→N, L→M, D→L, M→N, M→E, Z→E. A topological order lists…