CF1815F.OH NO1 (-2-3-4)

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an undirected graph with nn vertices and 3m3m edges. The graph may contain multi-edges, but does not contain self-loops.

The graph satisfies the following property: the given edges can be divided into mm groups of 33, such that each group is a triangle.

A triangle is defined as three edges (a,b)(a,b), (b,c)(b,c) and (c,a)(c,a) for some three distinct vertices a,b,ca,b,c (1≤a,b,c≤n1 \leq a,b,c \leq n).

Initially, each vertex vv has a non-negative integer weight ava_v. For every edge (u,v)(u,v) in the graph, you should perform the following operation exactly once:

  • Choose an integer xx between 11 and 44. Then increase both aua_u and ava_v by xx.

After performing all operations, the following requirement should be satisfied: if uu and vv are connected by an edge, then au≠ava_u \ne a_v.

It can be proven this is always possible under the constraints of the task. Output a way to do so, by outputting the choice of xx for each edge. It is easy to see that the order of operations does not matter. If there are multiple valid answers, output any.

你被给定一个包含 nn 个顶点和 3m3m 条边的无向图。该图可能包含重边,但不包含自环。

该图满足如下性质:所给的边可以被划分为 mm 组,每组恰好包含 3 条边,且每组构成一个三角形。

所谓三角形,是指对某三个互不相同的顶点 a,b,ca,b,c(其中 1≤a,b,c≤n1 \leq a,b,c \leq n),存在三条边 (a,b)(a,b)、(b,c)(b,c) 和 (c,a)(c,a)。

初始时,每个顶点 vv 都有一个非负整数权值 ava_v。对于图中的每条边 (u,v)(u,v),你需要恰好执行一次如下操作:

  • 选择一个介于 11 到 44 之间的整数 xx;然后将 aua_u 和 ava_v 同时增加 xx。

在执行完所有操作后,需满足如下要求:若顶点 uu 与 vv 之间存在一条边,则必须有 au≠ava_u \ne a_v。

在本题约束下,可以证明这样的方案总是存在的。请输出一种可行方案,即为每条边指定所选的 xx 值。显然,操作的执行顺序无关紧要。若存在多种合法答案,输出任意一种即可。

输入格式

The first line contains a single integer tt (1≤t≤1051 \leq t \leq 10^5) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and mm (3≤n≤1063 \le n \le 10^6, 1≤m≤4⋅1051 \le m \le 4 \cdot 10^5) — denoting the graph have nn vertices and 3m3m edges.

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai≤1060 \leq a_i \leq 10^6) — the initial weights of each vertex.

Then mm lines follow. The ii-th line contains three integers aia_i, bib_i, cic_i (1≤ai<bi<ci≤n1 \leq a_i \lt b_i \lt c_i \leq n) — denotes that three edges (ai,bi)(a_i,b_i), (bi,ci)(b_i,c_i) and (ci,ai)(c_i,a_i).

Note that the graph may contain multi-edges: a pair (x,y)(x,y) may appear in multiple triangles.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6 and the sum of mm over all test cases does not exceed 4⋅1054 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1051 \leq t \leq 10^5)——表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(3≤n≤1063 \le n \le 10^6,1≤m≤4⋅1051 \le m \le 4 \cdot 10^5)——表示该图有 nn 个顶点和 3m3m 条边。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai≤1060 \leq a_i \leq 10^6)——表示每个顶点的初始权重。

接下来是 mm 行。第 ii 行包含三个整数 aia_i、bib_i、cic_i(1≤ai<bi<ci≤n1 \leq a_i \lt b_i \lt c_i \leq n)——表示存在三条边 (ai,bi)(a_i,b_i)、(bi,ci)(b_i,c_i) 和 (ci,ai)(c_i,a_i)。

注意:该图可能包含重边,即某对顶点 (x,y)(x,y) 可能在多个三角形中出现。

保证所有测试用例的 nn 之和不超过 10610^6,且所有测试用例的 mm 之和不超过 4⋅1054 \cdot 10^5。

输出格式

For each test case, output mm lines of 33 integers each.

The ii-th line should contains three integers eab,ebc,ecae_{ab},e_{bc},e_{ca} (1≤eab,ebc,eca≤41 \leq e_{ab}, e_{bc} , e_{ca} \leq 4), denoting the choice of value xx for edges (ai,bi)(a_i, b_i), (bi,ci)(b_i,c_i) and (ci,ai)(c_i, a_i) respectively.

对每个测试用例,输出 mm 行,每行包含 33 个整数。

第 ii 行应包含三个整数 eab,ebc,ecae_{ab},e_{bc},e_{ca}(1≤eab,ebc,eca≤41 \leq e_{ab}, e_{bc} , e_{ca} \leq 4),分别表示边 (ai,bi)(a_i, b_i)、(bi,ci)(b_i,c_i) 和 (ci,ai)(c_i, a_i) 上所选择的值 xx。

输入输出样例

  • 输入#1

    4
    4 1
    0 0 0 0
    1 2 3
    5 2
    0 0 0 0 0
    1 2 3
    1 4 5
    4 4
    3 4 5 6
    1 2 3
    1 2 4
    1 3 4
    2 3 4
    5 4
    0 1000000 412 412 412
    1 2 3
    1 4 5
    2 4 5
    3 4 5

    输出#1

    2 1 3
    2 3 3
    4 3 3
    3 1 2
    2 2 3
    2 3 4
    3 1 1
    2 3 4
    1 2 4
    4 4 3
    4 1 1

说明/提示

In the first test case, the initial weights are [0,0,0,0][0,0,0,0]. We have added values as follows:

  • Added 22 to vertices 11 and 22
  • Added 11 to vertices 22 and 33
  • Added 33 to vertices 33 and 11

The final weights are [5,3,4,0][5,3,4,0]. The output is valid because a1≠a2a_1 \neq a_2, a1≠a3a_1 \neq a_3, a2≠a3a_2 \neq a_3, and that all chosen values are between 11 and 44.

In the second test case, the initial weights are [0,0,0,0,0][0,0,0,0,0]. The weights after the operations are [12,5,6,7,6][12,5,6,7,6]. The output is valid because a1≠a2a_1 \neq a_2, a1≠a3a_1 \neq a_3, a2≠a3a_2 \neq a_3, and that a1≠a4a_1 \neq a_4, a1≠a5a_1 \neq a_5, a4≠a5a_4 \neq a_5, and that all chosen values are between 11 and 44.

In the third test case, the initial weights are [3,4,5,6][3,4,5,6]. The weights after the operations are [19,16,17,20][19,16,17,20], and all final weights are distinct, which means no two adjacent vertices have the same weight.

在第一个测试用例中,初始权重为 [0,0,0,0][0,0,0,0]。我们按如下方式添加了数值:

  • 向顶点 11 和 22 各添加 22;
  • 向顶点 22 和 33 各添加 11;
  • 向顶点 33 和 11 各添加 33。

最终权重为 [5,3,4,0][5,3,4,0]。该输出合法,因为 a1≠a2a_1 \neq a_2、a1≠a3a_1 \neq a_3、a2≠a3a_2 \neq a_3,且所有所选值均在 11 到 44 之间。

在第二个测试用例中,初始权重为 [0,0,0,0,0][0,0,0,0,0]。操作后的权重为 [12,5,6,7,6][12,5,6,7,6]。该输出合法,因为 a1≠a2a_1 \neq a_2、a1≠a3a_1 \neq a_3、a2≠a3a_2 \neq a_3,且 a1≠a4a_1 \neq a_4、a1≠a5a_1 \neq a_5、a4≠a5a_4 \neq a_5,同时所有所选值均在 11 到 44 之间。

在第三个测试用例中,初始权重为 [3,4,5,6][3,4,5,6]。操作后的权重为 [19,16,17,20][19,16,17,20],且所有最终权重互不相同,这意味着任意两个相邻顶点的权重均不相等。

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

首页