atcoder#ARC079D. [ARC079F] Namori Grundy
[ARC079F] Namori Grundy
Score : points
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
.
4
2 3 4 1
POSSIBLE
The assignment is possible: {} = {} or {} {}.
3
2 3 1
IMPOSSIBLE
4
2 3 1 1
POSSIBLE
The assignment is possible: {} {}.
6
4 5 6 5 6 4
IMPOSSIBLE