← All problemsSign in

Connect All Cities

CodeChefRating 2417Open on judge ↗

The country of Berland initially has $N$ isolated cities, the $i$-th city has a significance of $A_i$. The President of Berland wants to connect all the cities. He can construct a bidirectional road of length $L$ $(L > 0)$ from city $X$ to city $Y$ if $(A_X \& A_Y \& L) = L$, where $\&$ represents the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) operator. What is the minimu

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