CF2115B.Gellyfish and Camellia Japonica
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Gellyfish has an array of n integers c1,c2,…,cn. In the beginning, c=[a1,a2,…,an].
Gellyfish will make q modifications to c.
For i=1,2,…,q, Gellyfish is given three integers xi, yi, and zi between 1 and n. Then Gellyfish will set czi:=min(cxi,cyi).
After the q modifications, c=[b1,b2,…,bn].
Now Flower knows the value of b and the value of the integers xi, yi, and zi for all 1≤i≤q, but she doesn't know the value of a.
Flower wants to find any possible value of the array a or report that no such a exists.
If there are multiple possible values of the array a, you may output any of them.
Gellyfish 有一个长度为 n 的整数数组 c1,c2,…,cn。初始时,c=[a1,a2,…,an]。
Gellyfish 将对 c 进行 q 次修改。
对于 i=1,2,…,q,Gellyfish 会得到三个介于 1 到 n 之间的整数 xi、yi 和 zi,然后执行赋值操作:czi:=min(cxi,cyi)。
经过这 q 次修改后,c=[b1,b2,…,bn]。
现在 Flower 知道了最终数组 b 的值,以及所有 1≤i≤q 对应的 xi、yi 和 zi 的值,但她不知道初始数组 a 的值。
Flower 希望找出任意一个可能的初始数组 a,或者判断不存在这样的 a。
如果存在多个可能的 a,你可以输出其中任意一个。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n,q≤3⋅105) — the size of the array and the number of modifications.
The second line of each test case contains n integers b1,b2,…,bn (1≤bi≤109) — the value of the array c after the q modifications.
The following q lines each contain three integers xi, yi, and zi (1≤xi,yi,zi≤n) — describing the i-th modification.
It is guaranteed that the sum of n and the sum of q over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤3⋅105)——分别表示数组的大小和修改操作的次数。
每个测试用例的第二行包含 n 个整数 b1,b2,…,bn(1≤bi≤109)——表示经过 q 次修改后数组 c 的值。
接下来的 q 行,每行包含三个整数 xi、yi 和 zi(1≤xi,yi,zi≤n)——描述第 i 次修改。
保证所有测试用例中 n 的总和与 q 的总和均不超过 3⋅105。
输出格式
For each test case, if a exists, output n integers a1,a2,…,an (0≤ai≤109) in a single line. Otherwise, output "-1" in a single line.
If there are multiple solutions, print any of them.
对于每个测试用例,如果存在满足条件的 a,则在一行中输出 n 个整数 a1,a2,…,an(其中 0≤ai≤109);否则,在一行中输出 “-1”。
如果有多个解,输出任意一个即可。
输入输出样例
输入#1
3 2 1 1 2 2 1 2 3 2 1 2 3 2 3 2 1 2 1 6 4 1 2 2 3 4 5 5 6 6 4 5 5 3 4 4 2 3 3
输出#1
-1 1 2 3 1 2 3 4 5 5
说明/提示
In the first test case, based on the given sequence of modifications, we know that b1=a1 and b2=min(a1,a2). Therefore, it is necessary that b2≤b1. However, for the given b, we have b1<b2. Therefore, there is no solution.
In the second test case, we can see that the given c becomes b from a after the given modifications, and c is not changed at each modification.
在第一个测试用例中,根据给定的修改序列,我们知道 b1=a1 且 b2=min(a1,a2)。因此,必须满足 b2≤b1。然而,对于给定的 b,有 b1<b2。因此,无解。
在第二个测试用例中,我们可以看出,给定的 c 在经过所描述的修改后,恰好变为 b(即由 a 变为 b),且 c 在每次修改中均保持不变。
输入解题思路,AI测评打分。不知道怎么写?