Valid Paths
You are given a tree with $N$ nodes numbered from $1$ to $N$. A set $S$ of nodes is called valid if there exist two vertices $u$ and $v$ (possibly, $u=v$) such that every node in $S$ lies on the simple path from $u$ to $v$. Count the number of valid sets modulo $10^9+7$. Two sets are different if one node is included in one set and not in the other. If there are multiple pairs $(u, v)$ making a
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