Permutation Cycle
CodeChefOpen on judge ↗
You are given a permutation $P$ of the integers $1$ to $N$, and an integer $K$. For this permutation $P$, let $G_P$ denote the undirected graph on $N$ vertices, which has edges between $i$ and $P_i$ for each $1 \leq i \leq N$ (and no other edges). It is well-known that each connected component of $G_P$ is a cycle. For each $x = 1, 2, \ldots, N$, solve the following problem **independently**:
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