Chef Cuts Tree
A forest is an undirected acyclic graph. Let us define the strength of a forest as the sum of squares of sizes of its connected components. (Clearly, a tree with n nodes has strength n2.) Chef has found a tree with N nodes on day 0. On each of the next N-1 days, he's going to remove one edge. Let's denote the forest that remains after i days by Fi, for each 1 ≤ i ≤ N-1; also, let's denote the or
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start