eolymp
bolt
Try our new interface for solving problems
Problems

Money Matters

Money Matters

Our sad tale begins with a tight clique of friends. Together they went on a trip to the picturesque country of Molvania. During their stay, various events which are too horrible to mention occurred. The net result was that the last evening of the trip ended with a momentous exchange of "I never want to see you again!"s. A quick calculation tells you it may have been said almost \textbf{50} million times! Back home in Scandinavia, our group of ex-friends realize that they haven't split the costs incurred during the trip evenly. Some people may be out several thousand crowns. Settling the debts turns out to be a bit more problematic than it ought to be, as many in the group no longer wish to speak to one another, and even less to give each other money. Naturally, you want to help out, so you ask each person to tell you how much money she owes or is owed, and whom she is still friends with. Given this information, you're sure you can figure out if it's possible for everyone to get even, and with money only being given between persons who are still friends. \InputFile The first line contains two integers \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{10000}) and \textbf{m} (\textbf{0} ≤ \textbf{m} ≤ \textbf{50000}), the number of friends and the number of remaining friendships. Then \textbf{n} lines follow, each containing an integer \textbf{o} (\textbf{-10000} ≤ \textbf{o} ≤ \textbf{10000}) indicating how much each person owes (or is owed if \textbf{o} < \textbf{0}). The sum of these values is zero. After this comes \textbf{m} lines giving the remaining friendships, each line containing two integers \textbf{x},\textit{ }\textbf{y} (\textbf{0} ≤ \textbf{x} < \textbf{y} ≤ \textbf{n}\textit{ }- \textbf{1}) indicating that persons \textbf{x} and \textbf{y} are still friends. \OutputFile Print a line saying "\textbf{POSSIBLE}" or "\textbf{IMPOSSIBLE}".
Time limit 1 second
Memory limit 128 MiB
Input example #1
5 3
100
-75
-25
-42
42
0 1
1 2
3 4
Output example #1
POSSIBLE
Source 2009 Nordic Collegiate Programming Contest, Октябрь 3, Задача B