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

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

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

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

A triangle are 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 ( 1a,b,cn1 \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 auava_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 do not matter. If there are multiple valid answers, output any.

输入格式

The first line contains a single integer tt ( 1t1051 \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 ( 3n1063 \le n \le 10^6 , 1m41051 \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 ( 0ai1060 \leq a_i \leq 10^6 ) — the initial weights of each vertex.

Then mm lines follows. The ii -th line contains three integers aia_i , bib_i , cic_i ( 1ai<bi<cin1 \leq a_i < b_i < 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 do not exceed 10610^6 and the sum of mm over all test cases do not exceed 41054 \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} ( 1eab,ebc,eca41 \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.

输入输出样例

  • 输入#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 11 and 33
  • Added 33 to vertices 22 and 33

The final weights are [3,5,4,0][3,5,4,0] . The output is valid because a1a2a_1 \neq a_2 , a1a3a_1 \neq a_3 , a2a3a_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 a1a2a_1 \neq a_2 , a1a3a_1 \neq a_3 , a2a3a_2 \neq a_3 , and that a1a4a_1 \neq a_4 , a1a5a_1 \neq a_5 , a4a5a_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] , so all final weights are distinct, which means no two adjacent vertices have the same weight.

首页