#K37927. Taco Coins Arrangement
Taco Coins Arrangement
Taco Coins Arrangement
You are given a set of coins and some adjacency restrictions. Each coin has a value and an implicit original index corresponding to its position in the input. The task is to determine whether it is possible to arrange the coins in increasing order of their values such that no two consecutive coins in the sorted order form a forbidden pair (provided as restrictions).
Formally, let the sorted order based on coin values be represented by an array \(A\) of coin indices. For every adjacent pair \(A[i]\) and \(A[i+1]\), the ordered pair \((\min(A[i], A[i+1]),\; \max(A[i], A[i+1]))\) must not appear in the given list of restrictions.
inputFormat
The first line of input contains two integers (n) and (m) where (n) is the number of coins and (m) is the number of restrictions. The second line contains (n) integers representing the coin values. This is followed by (m) lines, each containing two integers indicating a pair of coin indices that should not be adjacent in the final sorted order.
outputFormat
Print a single line: (POSSIBLE) if the coins can be arranged in increasing order without any restricted adjacent pairs, otherwise print (IMPOSSIBLE).## sample
4 2
1 3 2 4
1 2
3 4
POSSIBLE