← All problemsSign in

Tree Sum

You are given a connected undirected acyclic graph with $N$ vertices numbered $1$ to $N$, or in short, a tree. You are also given a parameter $K$ such that $1 \le K \le 2$. Let $dist(X, Y)$ denote the distance between the nodes $X$ and $Y$, or more formally, the number of edges on the unique simple path from $X$ to $Y$. For $3$ distinct vertices, $X$, $Y$ and $Z$, we define $f(X, Y, Z)$ as the

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