In the small country of Bytelandia there are
The King of Bytelandia is looking to enforce tariffs on these roads. For each road, he wants to assign one of the two noble houses to collect taxes on trade passing through that road. However, the King also has a secret secondary goal: to prevent either of the noble houses from staging a rebellion.
If a noble house starts a rebellion, it will succeed if and only if the house can supply weapons to all cities within Bytelandia using at most
The King has come to you to find a road assignment such that no noble house will be able to form a successful rebellion.
Constraints
For all
Subtask 1 [10%]
Subtask 2 [30%]
Subtask 3 [40%]
Subtask 4 [20%]
Input specification
The first line will contain two space seperated integers:
The next
These represent the adjacency matrix of the kingdom, with
Output specification
If no valid assignment exists, output the string IMPOSSIBLE
.
Otherwise output the string POSSIBLE
, following by
You must satisfy
If multiple valid assignments exist, any will be accepted.
Sample Input 1
3 1
011
101
110
Sample Output 1
IMPOSSIBLE
Sample Input 2
6 2
010001
101000
010100
001010
000101
100010
Sample Output 2
POSSIBLE
010002
102000
020100
001020
000201
200010
Explanation for Sample Output 2
The graph edges can be visualized in the following graph, where red and blue edges denote paths controlled by a given house.
It's clear that in the graph of blue edges no two nodes are sufficient to supply the entire rebellion, and the same holds for the graph of red edges.
Note
Due to subtask interactions, the samples are flipped in order. Samples 1 and 2 correspond to testcases #6 and #2 respectively.
Comments