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 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 −2⋅109-2 \cdot 10^9 to 2⋅1092 \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?

你必须处理一个非常复杂的供水系统。该系统由 nn 个节点和 mm 条管道组成,其中第 ii 条管道连接节点 xix_i 和 yiy_i。

你唯一能做的就是调节这些管道。你需要选择 mm 个整数 f1,f2,…,fmf_1, f_2, \dots, f_m 作为各管道的设定值。第 ii 条管道将每秒从节点 xix_i 向节点 yiy_i 输送 fif_i 单位的水(若 fif_i 为负,则该管道将每秒从节点 yiy_i 向节点 xix_i 输送 ∣fi∣|f_i| 单位的水)。允许将 fif_i 设为 −2⋅109-2 \cdot 10^9 到 2⋅1092 \cdot 10^9 范围内的任意整数。

为使系统正常运行,还需满足如下约束条件:对每个 i∈[1,n]i \in [1, n],第 ii 个节点均关联一个数值 sis_i,表示该节点的流入流量与流出流量之差必须恰好等于 sis_i(若 sis_i 非负,则第 ii 个节点每秒必须接收 sis_i 单位的水;若 sis_i 为负,则第 ii 个节点每秒必须向其他节点输送 ∣si∣|s_i| 单位的水)。

你能否选择整数 f1,f2,…,fmf_1, f_2, \dots, f_m,使得所有关于流入与流出流量的约束均被满足?

输入格式

The first line contains an integer nn (1≤n≤2⋅1051 \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 (−104≤si≤104-10^4 \le s_i \le 10^4) — constraints for the junctions.

The third line contains an integer mm (0≤m≤2⋅1050 \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 (1≤xi,yi≤n1 \le x_i, y_i \le n, xi≠yix_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.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示节点的数量。

第二行包含 nn 个整数 s1,s2,…,sns_1, s_2, \dots, s_n(−104≤si≤104-10^4 \le s_i \le 10^4)—— 表示各节点的约束条件。

第三行包含一个整数 mm(0≤m≤2⋅1050 \le m \le 2 \cdot 10^5)—— 表示管道的数量。

接下来的 mm 行中,第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤n1 \le x_i, y_i \le n,且 xi≠yix_i \ne y_i)—— 描述第 ii 条管道。保证输入中每个无序对 (x,y)(x, y) 至多出现一次(即在 (x,y)(x, y) 首次出现后,不会再出现 (x,y)(x, y) 或 (y,x)(y, x))。保证任意两个节点之间均存在一条沿管道构成的路径。

输出格式

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.

如果可以选出满足所有入流和出流要求的整数 f1,f2,…,fmf_1, f_2, \dots, f_m,则在第一行输出 "Possible";随后输出 mm 行,其中第 ii 行应包含 fif_i —— 即为第 ii 条管道选择的设定值(管道按其在输入中出现的顺序编号)。

否则,仅在一行中输出 "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测评打分。不知道怎么写?

首页