← All problemsSign in

Chef, Primes and Trees (Challenge)

CodeChefRating 3579Open on judge ↗

Chef loves prime numbers and trees. One day, Chef received $N$ nodes (numbered $1$ through $N$) as a gift. There are no edges between them yet, but each node contains a value; let's denote the value in node $i$ by $V_i$. Since Chef likes trees, he wants to form a tree by adding $N-1$ edges between these nodes. Chef defines a subtree as any connected component obtained after deleting an edge. A 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