CF1717F.Madoka and The First Session
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Oh no, on the first exam Madoka got this hard problem:
Given integer n and m pairs of integers (vi,ui). Also there is an array b1,b2,…,bn, initially filled with zeros.
Then for each index i, where 1≤i≤m, perform either bvi:=bvi−1 and bui:=bui+1, or bvi:=bvi+1 and bui:=bui−1. Note that exactly one of these operations should be performed for every i.
Also there is an array s of length n consisting of 0 and 1. And there is an array a1,a2,…,an, where it is guaranteed, that if si=0 holds, then ai=0.
Help Madoka and determine whenever it is possible to perform operations in such way that for every i, where si=1 it holds that ai=bi. If it possible you should also provide Madoka with a way to perform operations.
糟糕,魔法少女小圆第一次考试就遇到了这道难题:
给定整数 n 和 m 对整数 (vi,ui)。另有一个长度为 n 的数组 b1,b2,…,bn,初始时所有元素均为 0。
接着,对每个下标 i(其中 1≤i≤m),执行以下两种操作之一:
- bvi:=bvi−1 且 bui:=bui+1,
- 或 bvi:=bvi+1 且 bui:=bui−1。
注意:对每个 i,必须且仅能选择上述两种操作中的一种执行。
此外,还有一个长度为 n 的由 0 和 1 组成的数组 s,以及一个数组 a1,a2,…,an,满足如下条件:若 si=0,则必有 ai=0。
请帮助小圆判断:是否存在一种操作方式,使得对每个满足 si=1 的下标 i,均有 ai=bi?若存在,请同时给出一种可行的操作方案。
输入格式
The first line contains two integers n and m (2≤n≤10000,1≤m≤10000) — the length of the array a and the number of pair of integers.
The second line contains n integers s1,s2,…sn (0≤si≤1) — the elements of the array s.
The third line contains n integers a1,a2,…,an (∣ai∣≤m) — the elements of the array a. It is guaranteed that if si=0 holds, then ai=0.
i-th of the following m lines contains two integers vi and ui (1≤vi,ui≤n,vi=ui) — the indexes of the elements of the array b to which the operation is performed. It is also guaranteed that there are no two indices i and j, where 1≤i<j≤m, such that (vi,ui)=(vj,uj) or (vi,ui)=(uj,vj).
第一行包含两个整数 n 和 m(2≤n≤10000, 1≤m≤10000)—— 分别表示数组 a 的长度以及整数对的数量。
第二行包含 n 个整数 s1,s2,…,sn(0≤si≤1)—— 表示数组 s 的元素。
第三行包含 n 个整数 a1,a2,…,an(∣ai∣≤m)—— 表示数组 a 的元素。保证:若 si=0,则必有 ai=0。
接下来的 m 行中,第 i 行包含两个整数 vi 和 ui(1≤vi,ui≤n, vi=ui)—— 表示对数组 b 中下标为 vi 和 ui 的元素执行操作。此外还保证:不存在满足 1≤i<j≤m 的两个下标 i 和 j,使得 (vi,ui)=(vj,uj) 或 (vi,ui)=(uj,vj)。
输出格式
In the first line print "YES" if it is possible to perform operations in the required way, and "NO" otherwise.
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
In case you printed "YES", print m pairs of integers. If for pair (vi,ui) we should perform bvi:=bvi−1 and bui:=bui+1, print (vi,ui). Otherwise print (ui,vi). If there are multiple ways to get the correct answer, you can print any of them.
You can print pairs in any order.
第一行输出“YES”(如果可以按要求的方式执行操作),否则输出“NO”。
每个字母的大小写不限(例如,“YES”、“Yes”、“yes”、“yEs”均被视为肯定回答)。
若你输出了“YES”,则接下来输出 m 对整数。对于第 i 对 (vi,ui),若应执行操作 bvi:=bvi−1 和 bui:=bui+1,则输出 (vi,ui);否则输出 (ui,vi)。若存在多种可行方案,输出任意一种即可。
各对整数的输出顺序不限。
输入输出样例
输入#1
5 5 1 1 1 1 1 -2 0 2 1 -1 1 5 1 4 3 5 3 4 4 5
输出#1
YES 1 5 1 4 5 3 4 3 5 4
输入#2
5 5 0 1 0 1 0 0 1 0 0 0 1 3 2 3 3 5 3 4 4 5
输出#2
YES 3 1 3 2 5 3 3 4 4 5
输入#3
4 4 1 1 1 1 0 2 -2 2 1 3 1 4 2 3 2 4
输出#3
NO
说明/提示
In the first example, the array b will change as follows: [0,0,0,0,0]→[−1,0,0,1,0]→[−2,0,0,1,1]→[−2,0,1,0,1]→[−2,0,2,0,0]→[−2,0,2,1,−1]. ai=bi for all indices i from 1 to 5.
In the second example, it is enough for us that b2=1 at the end, since only s2=1.
In the third example, the operations cannot be performed as required.
在第一个例子中,数组 b 的变化过程如下:[0,0,0,0,0]→[−1,0,0,1,0]→[−2,0,0,1,1]→[−2,0,1,0,1]→[−2,0,2,0,0]→[−2,0,2,1,−1]。对所有从 1 到 5 的下标 i,均有 ai=bi。
在第二个例子中,只需最终满足 b2=1 即可,因为仅有 s2=1。
在第三个例子中,无法按要求执行操作。
输入解题思路,AI测评打分。不知道怎么写?