fuel

Time limit: 0.3s Memory limit: 256MB Input: Output:

With the recent stock market crash, gas stations in Gabrovo have fallen into crisis. Kyusho regularly fills up his car in Gabrovo, but with today’s increased gas prices, he has no choice but to use public transportation. Faced with such a difficult choice, Kyusho set out to fix the situation.

There are NN gas stations in Gabrovo in total, numbered from 11 to NN, with MM bidirectional streets, each of which connecting two different gas stations. There is at most one street between each pair of gas stations. From each gas station, you can reach any other by moving along the streets. Each gas station has a fuel balance — an integer cic_i (it is possible for the balance to be negative). From time to time, a gas station drains fuel from all its neighbors (those to which there is a direct street), thus increasing its balance by kik_i, where kik_i is the number of neighboring gas stations. In the same time, their balance decreases by one (even if it is already negative).

Kyusho knows that the people of Gabrovo will continue to pump fuel from each other until they all end up with a non-negative balance. Using his connections, he can convince each of them to rob his neighbors a certain number of times. But that’s where the problem comes in — Kyusho is not sure how to end up with no gas stations with a negative balance.

Task

Help Kyusho by writing a program that, given a map of gas stations and their balances, finds what instructions Kyusho should give.

Input data

The first line of the standard input contains two natural number NN and MM — the number of gas stations and the number of bidirectional streets between them. The next line contains NN space-separated integers cic_i — the balances of the gas stations. Еach of the the last MM lines contains two different numbers AA and BB, indicating that there is a street between gas stations with numbers AA and BB.

Output data

If no solution exists, print Impossible on the only line of standard output. Otherwise, print Possible on the first line. On the next line print NN integers wiw_i, separated by a space — how many times each of the gas stations must drain its neighbors so that in the end they all have a non-negative balance. Your solution is considered correct if in the end each gas station has a non-negative balance and for every 1iN1 \leq i \leq N it is satisfied that 0wi10180 \leq w_i \leq 10^{18}.

Constraints and clarifications

  • 1N1051 \leq N \leq 10^5
  • N1MNN - 1 \leq M \leq N
  • 104ci104-10^4 \leq c_i \leq 10^4
  • 1A,BN1 \leq A,B \leq N, ABA \neq B
  • From each gas station you can reach any other by moving along the streets.
Subtask Points Required subtasks NN MM Other constraints
0 0 The example test cases.
1 5 105\leq 10^5 =N1= N - 1 All streets are between gas stations with consecutive numbers and cici+1c_i \leq c_{i+1} for each 1iN11 \leq i \leq N-1.
2 12 2 000\leq 2 \ 000 =N1= N - 1 All streets are between gas stations with consecutive numbers.
3 7 105\leq 10^5 =N1= N - 1 All gas stations apart from one have exactly one neighboring gas station.
4 15 500\leq 500 =N1= N - 1
5 12 2, 4 2 000\leq 2 \ 000 =N1= N - 1
6 14 1–5 105\leq 10^5 =N1= N - 1
7 16 2 000\leq 2 \ 000 N\leq N c1+c2+...+cN0c_1 + c_2 + ... + c_N \not= 0
8 13 2, 4, 5, 7 2 000\leq 2 \ 000 N\leq N
9 6 0–8 105\leq 10^5 N\leq N

Example 1

stdin

7 6
-4 -3 6 0 4 -7 5
2 1
1 3
1 4
4 5
4 6
6 7

stdout

Possible
6 9 0 4 0 6 1

Explanation

Gas station 11 robs its neighbors 66 times, increasing its balance by 63=186 \cdot 3 = 18, but it is also robbed 9+0+4=139 + 0 + 4 = 13 times, making its final balance equal to 4+1813=1−4 + 18 − 13 = 1. All other gas stations are left with zero balance.
Illustration of the gas stations and initial balances:

Example 2

stdin

7 7
0 1 -1 4 -3 -1 1
1 2
2 3
3 4
4 5
5 1
1 6
4 7

stdout

Possible
4 3 3 1 4 5 0

Explanation

After following Kyusho’s instructions, all gas stations have a balance of 00, except for the one with number 33, which has a balance of 11.

Example 3

stdin

3 3
1 0 -1
1 2
2 3
1 3

stdout

Impossible

Explanation

No matter how gas stations rob each other, they will always never all have a nonnegative balance.

Log in or sign up to be able to send submissions!