CF990F.Flow Control
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
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?
你必须处理一个非常复杂的供水系统。该系统由 n 个节点和 m 条管道组成,其中第 i 条管道连接节点 xi 和 yi。
你唯一能做的就是调节这些管道。你需要选择 m 个整数 f1,f2,…,fm 作为各管道的设定值。第 i 条管道将每秒从节点 xi 向节点 yi 输送 fi 单位的水(若 fi 为负,则该管道将每秒从节点 yi 向节点 xi 输送 ∣fi∣ 单位的水)。允许将 fi 设为 −2⋅109 到 2⋅109 范围内的任意整数。
为使系统正常运行,还需满足如下约束条件:对每个 i∈[1,n],第 i 个节点均关联一个数值 si,表示该节点的流入流量与流出流量之差必须恰好等于 si(若 si 非负,则第 i 个节点每秒必须接收 si 单位的水;若 si 为负,则第 i 个节点每秒必须向其他节点输送 ∣si∣ 单位的水)。
你能否选择整数 f1,f2,…,fm,使得所有关于流入与流出流量的约束均被满足?
输入格式
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.
第一行包含一个整数 n(1≤n≤2⋅105)—— 表示节点的数量。
第二行包含 n 个整数 s1,s2,…,sn(−104≤si≤104)—— 表示各节点的约束条件。
第三行包含一个整数 m(0≤m≤2⋅105)—— 表示管道的数量。
接下来的 m 行中,第 i 行包含两个整数 xi 和 yi(1≤xi,yi≤n,且 xi=yi)—— 描述第 i 条管道。保证输入中每个无序对 (x,y) 至多出现一次(即在 (x,y) 首次出现后,不会再出现 (x,y) 或 (y,x))。保证任意两个节点之间均存在一条沿管道构成的路径。
输出格式
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.
如果可以选出满足所有入流和出流要求的整数 f1,f2,…,fm,则在第一行输出 "Possible";随后输出 m 行,其中第 i 行应包含 fi —— 即为第 i 条管道选择的设定值(管道按其在输入中出现的顺序编号)。
否则,仅在一行中输出 "Impossible"。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?