CF990F.Flow Control

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have to handle a very complex water distribution system. The system consists of nn junctions and mm pipes, ii -th pipe connects junctions xix_i and yiy_i .

The only thing you can do is adjusting the pipes. You have to choose mm integer numbers f1f_1 , f2f_2 , ..., fmf_m and use them as pipe settings. ii -th pipe will distribute fif_i units of water per second from junction xix_i to junction yiy_i (if fif_i is negative, then the pipe will distribute fi|f_i| units of water per second from junction yiy_i to junction xix_i ). It is allowed to set fif_i to any integer from 2109-2 \cdot 10^9 to 21092 \cdot 10^9 .

In order for the system to work properly, there are some constraints: for every i[1,n]i \in [1, n] , ii -th junction has a number sis_i associated with it meaning that the difference between incoming and outcoming flow for ii -th junction must be exactly sis_i (if sis_i is not negative, then ii -th junction must receive sis_i units of water per second; if it is negative, then ii -th junction must transfer si|s_i| units of water per second to other junctions).

Can you choose the integers f1f_1 , f2f_2 , ..., fmf_m in such a way that all requirements on incoming and outcoming flows are satisfied?

输入格式

The first line contains an integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the number of junctions.

The second line contains nn integers s1,s2,,sns_1, s_2, \dots, s_n ( 104si104-10^4 \le s_i \le 10^4 ) — constraints for the junctions.

The third line contains an integer mm ( 0m21050 \le m \le 2 \cdot 10^5 ) — the number of pipes.

ii -th of the next mm lines contains two integers xix_i and yiy_i ( 1xi,yin1 \le x_i, y_i \le n , xiyix_i \ne y_i ) — the description of ii -th pipe. It is guaranteed that each unordered pair (x,y)(x, y) will appear no more than once in the input (it means that there won't be any pairs (x,y)(x, y) or (y,x)(y, x) after the first occurrence of (x,y)(x, y) ). It is guaranteed that for each pair of junctions there exists a path along the pipes connecting them.

输出格式

If you can choose such integer numbers f1,f2,,fmf_1, f_2, \dots, f_m in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output mm lines, ii -th line should contain fif_i — the chosen setting numbers for the pipes. Pipes are numbered in order they appear in the input.

Otherwise output "Impossible" in the only line.

输入输出样例

  • 输入#1

    4
    3 -10 6 1
    5
    1 2
    3 2
    2 4
    3 4
    3 1
    

    输出#1

    Possible
    4
    -6
    8
    -7
    7
    
  • 输入#2

    4
    3 -10 6 4
    5
    1 2
    3 2
    2 4
    3 4
    3 1
    

    输出#2

    Impossible
    
首页