← All problemsSign in

Chef and Pairs

CodeChefRating 2896Open on judge ↗

You are given a tree (connected, undirected, acyclic graph) consisting of $N$ nodes. Based on this tree, you have to answer $Q$ queries. Each query is of the form: - $K\ D\ V_1\ V_2\ \cdots\ V_K$ - output the number of pairs $(i, j)$, $1 \leq i \lt j \leq K$, such that the shortest path between nodes $V_i$ and $V_j$ in the tree has $D$ edges. ### Input - The first line contains an integer $T

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