{"problem":{"name":"Namori Grundy","description":{"content":"There is a directed graph with $N$ vertices and $N$ edges. The vertices are numbered $1, 2, ..., N$. The graph has the following $N$ edges: $(p_1, 1), (p_2, 2), ..., (p_N, N)$, and the graph is weakly","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc079_d"},"statements":[{"statement_type":"Markdown","content":"There is a directed graph with $N$ vertices and $N$ edges. The vertices are numbered $1, 2, ..., N$.\nThe graph has the following $N$ edges: $(p_1, 1), (p_2, 2), ..., (p_N, N)$, and the graph is weakly connected. Here, an edge from Vertex $u$ to Vertex $v$ is denoted by $(u, v)$, and a weakly connected graph is a graph which would be connected if each edge was bidirectional.\nWe would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, $a_i$ is the value assigned to Vertex $i$.\n\n*   Each $a_i$ is a non-negative integer.\n*   For each edge $(i, j)$, $a_i \\neq a_j$ holds.\n*   For each $i$ and each integer $x(0 ≤ x < a_i)$, there exists a vertex $j$ such that the edge $(i, j)$ exists and $x = a_j$ holds.\n\nDetermine whether there exists such an assignment.\n\n## Constraints\n\n*   $2 ≤ N ≤ 200$ $000$\n*   $1 ≤ p_i ≤ N$\n*   $p_i \\neq i$\n*   The graph is weakly connected.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$p_1$ $p_2$ ... $p_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc079_d","tags":[],"sample_group":[["4\n2 3 4 1","POSSIBLE\n\nThe assignment is possible: {$a_i$} = {$0, 1, 0, 1$} or {$a_i$} $=$ {$1, 0, 1, 0$}."],["3\n2 3 1","IMPOSSIBLE"],["4\n2 3 1 1","POSSIBLE\n\nThe assignment is possible: {$a_i$} $=$ {$2, 0, 1, 0$}."],["6\n4 5 6 5 6 4","IMPOSSIBLE"]],"created_at":"2026-03-03 11:01:14"}}