Optimal Splitting
Given a tree with n nodes. Split it into 3 parts such that all the three parts are connected components in original graph and each node is exactly present in one of the parts and the following function is minimised: Let s1,s2,s3 be the sizes of the 3 parts (or connected components) then $f=|s1-s2|+|s2-s3|+|s1-s3|$ Also calculate the number of ways of splitting the tree. Two ways are considere
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