#arc079d. [arc079_d]Namori Grundy
[arc079_d]Namori Grundy
Problem Statement
There is a directed graph with vertices and edges. The vertices are numbered .
The graph has the following edges: , and the graph is weakly connected. Here, an edge from Vertex to Vertex is denoted by , 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, is the value assigned to Vertex .
- Each is a non-negative integer.
- For each edge , holds.
- For each and each integer , there exists a vertex such that the edge exists and holds.
Determine whether there exists such an assignment.
Constraints
- The graph is weakly connected.
Input
Input is given from Standard Input in the following format:
...
Output
If the assignment is possible, print POSSIBLE
; otherwise, print IMPOSSIBLE
.
Sample Input 1
4
2 3 4 1
Sample Output 1
POSSIBLE
The assignment is possible: {} = {} or {} \= {}.
Sample Input 2
3
2 3 1
Sample Output 2
IMPOSSIBLE
Sample Input 3
4
2 3 1 1
Sample Output 3
POSSIBLE
The assignment is possible: {} \= {}.
Sample Input 4
6
4 5 6 5 6 4
Sample Output 4
IMPOSSIBLE