← All problemsSign in

Roads

Sarah is an engineer assigned to build roads between the N towns of Evoland. Towns are assigned IDs from 1 to N. A road connects exactly one pair of towns, and is bidirectional. The mayor of Evoland allocated a very small budget for this project. Thus, Sarah is forced to build as few roads as possible while still keeping all N towns connected via roads. Note that this is an absolute requirement;

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