Skip to main content

Practice · 2 of 3

Every Node Wants the Crown

CHALLENGE
Difficulty: advanced+25 XP

**Scenario.** Tree, n ≤ 200000: for every vertex, the sum of distances to all others. What is the intended technique? **Which approach is the best fit? The program only needs to print the letter.** **A)** Run BFS from every vertex — O(n²) but constants are small **B)** One post-order DP for subtree contributions, then one pre-order reroot pass with an O(1) exchange per edge **C)** Floyd–Warshall on the tree **D)** Binary lifting to LCA, then sum pairwise distances

Back to lesson: Practice: Graph Synthesis Drills