Reach Anywhere
You are given a simple undirected graph with $N$ vertices and $M$ edges. Find the smallest non-negative integer $K$ such that for *every* vertex $u$ ($1 \leq u \leq N$), there exists a [*walk*](https://mathworld.wolfram.com/Walk.html) of length **exactly** $K$ from $1$ to $u$. If no such integer exists, print $-1$ instead. **Notes:** - It is allowed to repeat both vertices and edges in a walk.
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