← All problemsSign in

A Special Tree

CodeChefRating 2350Open on judge ↗

You are given a tree with $N$ nodes (numbered $1$ through $N$). There are $K$ special nodes $f_1,f_2,\ldots,f_K$ in this tree. We define $d(p,q)$ to be the number of edges on the unique path from node $p$ to node $q$. You are given a node $a$. For each node $b$ from $1$ to $N$, find the maximum value of $d(a,u)-d(b,u)$ where $u$ is a special node, as well as any special node $u$ for which that m

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