Soumya wants to buy a tree
CodeChefOpen on judge ↗
Soumya wants to purchase a tree. You have an unrooted tree having $N$ nodes. If you root the tree at node $X$, then Cost of tree = $\sum_{i=1}^n$ {$(-1)$$(dis[i])$ $*A[i] *dis[i]$}, where $dis[i]$ denotes distance of node $i$ from $X$ i.e. the number of edges in the shortest path connecting them. As you are Soumya's friend, you would like to sell her the tree for the least possible cost :) Find ou
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