← All problemsSign in

Color Score

CodeChefRating 2816Open on judge ↗

You are given a tree with $N$ nodes rooted at node $1$. Each node $i$ has an associated color $C_i$ and a value $V_i$. For any tree with **at least two** nodes, the **score** for a partition (obtained by removing a **single leaf** — that is, a node with degree $1$) is defined as the sum, over all colors, of the absolute differences between the total values of nodes with that color in the two resu

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start