Score : $800$ points
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 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.
We 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$.
Determine whether there exists such an assignment.
Input is given from Standard Input in the following format:
$N$ $p_1$ $p_2$ ... $p_N$
If the assignment is possible, print POSSIBLE
; otherwise, print IMPOSSIBLE
.
4 2 3 4 1
POSSIBLE
The assignment is possible: {$a_i$} = {$0, 1, 0, 1$} or {$a_i$} $=$ {$1, 0, 1, 0$}.
3 2 3 1
IMPOSSIBLE
4 2 3 1 1
POSSIBLE
The assignment is possible: {$a_i$} $=$ {$2, 0, 1, 0$}.
6 4 5 6 5 6 4
IMPOSSIBLE