题目描述
题目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: (p1,1),(p2,2),…,(pN,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, ai is the value assigned to Vertex i.
Each ai is a non-negative integer.
For each edge (i,j), ai≠aj holds.
For each i and each integer x(0≤x<ai), there exists a vertex j such that the edge (i,j) exists and x=aj holds.
Determine whether there exists such an assignment.
Constraints
2≤N≤200 000
1≤pi≤N
pi≠i
The graph is weakly connected.
输入
Input is given from Standard Input in the following format:
N
p1 p2 ... pN
输出
If the assignment is possible, print POSSIBLE; otherwise, print IMPOSSIBLE.
样例输入 Copy
4
2 3 4 1
样例输出 Copy
POSSIBLE
提示
The assignment is possible: {ai} = {0,1,0,1} or {ai} = {1,0,1,0}.