CF990F.Flow Control
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have to handle a very complex water distribution system. The system consists of n junctions and m pipes, i -th pipe connects junctions xi and yi .
The only thing you can do is adjusting the pipes. You have to choose m integer numbers f1 , f2 , ..., fm and use them as pipe settings. i -th pipe will distribute fi units of water per second from junction xi to junction yi (if fi is negative, then the pipe will distribute ∣fi∣ units of water per second from junction yi to junction xi ). It is allowed to set fi to any integer from −2⋅109 to 2⋅109 .
In order for the system to work properly, there are some constraints: for every i∈[1,n] , i -th junction has a number si associated with it meaning that the difference between incoming and outcoming flow for i -th junction must be exactly si (if si is not negative, then i -th junction must receive si units of water per second; if it is negative, then i -th junction must transfer ∣si∣ units of water per second to other junctions).
Can you choose the integers f1 , f2 , ..., fm in such a way that all requirements on incoming and outcoming flows are satisfied?
输入格式
The first line contains an integer n ( 1≤n≤2⋅105 ) — the number of junctions.
The second line contains n integers s1,s2,…,sn ( −104≤si≤104 ) — constraints for the junctions.
The third line contains an integer m ( 0≤m≤2⋅105 ) — the number of pipes.
i -th of the next m lines contains two integers xi and yi ( 1≤xi,yi≤n , xi=yi ) — the description of i -th pipe. It is guaranteed that each unordered pair (x,y) will appear no more than once in the input (it means that there won't be any pairs (x,y) or (y,x) after the first occurrence of (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,…,fm in such a way that all requirements on incoming and outcoming flows are satisfied, then output "Possible" in the first line. Then output m lines, i -th line should contain fi — 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