CF2115B.Gellyfish and Camellia Japonica

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gellyfish has an array of nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n. In the beginning, c=[a1,a2,…,an]c = [a_1, a_2, \ldots, a_n].

Gellyfish will make qq modifications to cc.

For i=1,2,…,qi = 1,2,\ldots,q, Gellyfish is given three integers xix_i, yiy_i, and ziz_i between 11 and nn. Then Gellyfish will set czi:=min⁡(cxi,cyi)c_{z_i} := \min(c_{x_i}, c_{y_i}).

After the qq modifications, c=[b1,b2,…,bn]c = [b_1, b_2, \ldots, b_n].

Now Flower knows the value of bb and the value of the integers xix_i, yiy_i, and ziz_i for all 1≤i≤q1 \leq i \leq q, but she doesn't know the value of aa.

Flower wants to find any possible value of the array aa or report that no such aa exists.

If there are multiple possible values of the array aa, you may output any of them.

Gellyfish 有一个长度为 nn 的整数数组 c1,c2,…,cnc_1, c_2, \ldots, c_n。初始时,c=[a1,a2,…,an]c = [a_1, a_2, \ldots, a_n]。

Gellyfish 将对 cc 进行 qq 次修改。

对于 i=1,2,…,qi = 1,2,\ldots,q,Gellyfish 会得到三个介于 11 到 nn 之间的整数 xix_i、yiy_i 和 ziz_i,然后执行赋值操作:czi:=min⁡(cxi,cyi)c_{z_i} := \min(c_{x_i}, c_{y_i})。

经过这 qq 次修改后,c=[b1,b2,…,bn]c = [b_1, b_2, \ldots, b_n]。

现在 Flower 知道了最终数组 bb 的值,以及所有 1≤i≤q1 \leq i \leq q 对应的 xix_i、yiy_i 和 ziz_i 的值,但她不知道初始数组 aa 的值。

Flower 希望找出任意一个可能的初始数组 aa,或者判断不存在这样的 aa。

如果存在多个可能的 aa,你可以输出其中任意一个。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains two integers nn and qq (1≤n,q≤3⋅1051 \leq n, q \leq 3 \cdot 10^5) — the size of the array and the number of modifications.

The second line of each test case contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n (1≤bi≤1091 \leq b_i \leq 10^9) — the value of the array cc after the qq modifications.

The following qq lines each contain three integers xix_i, yiy_i, and ziz_i (1≤xi,yi,zi≤n1 \leq x_i, y_i, z_i \leq n) — describing the ii-th modification.

It is guaranteed that the sum of nn and the sum of qq over all test cases does not exceed 3⋅1053 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n,q≤3⋅1051 \leq n, q \leq 3 \cdot 10^5)——分别表示数组的大小和修改操作的次数。

每个测试用例的第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(1≤bi≤1091 \leq b_i \leq 10^9)——表示经过 qq 次修改后数组 cc 的值。

接下来的 qq 行,每行包含三个整数 xix_i、yiy_i 和 ziz_i(1≤xi,yi,zi≤n1 \leq x_i, y_i, z_i \leq n)——描述第 ii 次修改。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, if aa exists, output nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9) in a single line. Otherwise, output "-1" in a single line.

If there are multiple solutions, print any of them.

对于每个测试用例,如果存在满足条件的 aa,则在一行中输出 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(其中 0≤ai≤1090 \leq a_i \leq 10^9);否则,在一行中输出 “-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=a1b_1 = a_1 and b2=min⁡(a1,a2)b_2 = \min(a_1, a_2). Therefore, it is necessary that b2≤b1b_2 \leq b_1. However, for the given bb, we have b1<b2b_1 \lt b_2. Therefore, there is no solution.

In the second test case, we can see that the given cc becomes bb from aa after the given modifications, and cc is not changed at each modification.

在第一个测试用例中,根据给定的修改序列,我们知道 b1=a1b_1 = a_1 且 b2=min⁡(a1,a2)b_2 = \min(a_1, a_2)。因此,必须满足 b2≤b1b_2 \leq b_1。然而,对于给定的 bb,有 b1<b2b_1 \lt b_2。因此,无解。

在第二个测试用例中,我们可以看出,给定的 cc 在经过所描述的修改后,恰好变为 bb(即由 aa 变为 bb),且 cc 在每次修改中均保持不变。

输入解题思路,AI测评打分。不知道怎么写?

首页