CF1815F.OH NO1 (-2-3-4)
NOI/NOI+/CTSC
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an undirected graph with n vertices and 3m 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 m groups of 3, such that each group is a triangle.
A triangle is defined as three edges (a,b), (b,c) and (c,a) for some three distinct vertices a,b,c (1≤a,b,c≤n).
Initially, each vertex v has a non-negative integer weight av. For every edge (u,v) in the graph, you should perform the following operation exactly once:
- Choose an integer x between 1 and 4. Then increase both au and av by x.
After performing all operations, the following requirement should be satisfied: if u and v are connected by an edge, then au=av.
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 x for each edge. It is easy to see that the order of operations does not matter. If there are multiple valid answers, output any.
你被给定一个包含 n 个顶点和 3m 条边的无向图。该图可能包含重边,但不包含自环。
该图满足如下性质:所给的边可以被划分为 m 组,每组恰好包含 3 条边,且每组构成一个三角形。
所谓三角形,是指对某三个互不相同的顶点 a,b,c(其中 1≤a,b,c≤n),存在三条边 (a,b)、(b,c) 和 (c,a)。
初始时,每个顶点 v 都有一个非负整数权值 av。对于图中的每条边 (u,v),你需要恰好执行一次如下操作:
- 选择一个介于 1 到 4 之间的整数 x;然后将 au 和 av 同时增加 x。
在执行完所有操作后,需满足如下要求:若顶点 u 与 v 之间存在一条边,则必须有 au=av。
在本题约束下,可以证明这样的方案总是存在的。请输出一种可行方案,即为每条边指定所选的 x 值。显然,操作的执行顺序无关紧要。若存在多种合法答案,输出任意一种即可。
输入格式
The first line contains a single integer t (1≤t≤105) — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers n and m (3≤n≤106, 1≤m≤4⋅105) — denoting the graph have n vertices and 3m edges.
The second line of each test case contains n integers a1,a2,…,an (0≤ai≤106) — the initial weights of each vertex.
Then m lines follow. The i-th line contains three integers ai, bi, ci (1≤ai<bi<ci≤n) — denotes that three edges (ai,bi), (bi,ci) and (ci,ai).
Note that the graph may contain multi-edges: a pair (x,y) may appear in multiple triangles.
It is guaranteed that the sum of n over all test cases does not exceed 106 and the sum of m over all test cases does not exceed 4⋅105.
第一行包含一个整数 t(1≤t≤105)——表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(3≤n≤106,1≤m≤4⋅105)——表示该图有 n 个顶点和 3m 条边。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤106)——表示每个顶点的初始权重。
接下来是 m 行。第 i 行包含三个整数 ai、bi、ci(1≤ai<bi<ci≤n)——表示存在三条边 (ai,bi)、(bi,ci) 和 (ci,ai)。
注意:该图可能包含重边,即某对顶点 (x,y) 可能在多个三角形中出现。
保证所有测试用例的 n 之和不超过 106,且所有测试用例的 m 之和不超过 4⋅105。
输出格式
For each test case, output m lines of 3 integers each.
The i-th line should contains three integers eab,ebc,eca (1≤eab,ebc,eca≤4), denoting the choice of value x for edges (ai,bi), (bi,ci) and (ci,ai) respectively.
对每个测试用例,输出 m 行,每行包含 3 个整数。
第 i 行应包含三个整数 eab,ebc,eca(1≤eab,ebc,eca≤4),分别表示边 (ai,bi)、(bi,ci) 和 (ci,ai) 上所选择的值 x。
输入输出样例
输入#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]. We have added values as follows:
- Added 2 to vertices 1 and 2
- Added 1 to vertices 2 and 3
- Added 3 to vertices 3 and 1
The final weights are [5,3,4,0]. The output is valid because a1=a2, a1=a3, a2=a3, and that all chosen values are between 1 and 4.
In the second test case, the initial weights are [0,0,0,0,0]. The weights after the operations are [12,5,6,7,6]. The output is valid because a1=a2, a1=a3, a2=a3, and that a1=a4, a1=a5, a4=a5, and that all chosen values are between 1 and 4.
In the third test case, the initial weights are [3,4,5,6]. The weights after the operations are [19,16,17,20], and all final weights are distinct, which means no two adjacent vertices have the same weight.
在第一个测试用例中,初始权重为 [0,0,0,0]。我们按如下方式添加了数值:
- 向顶点 1 和 2 各添加 2;
- 向顶点 2 和 3 各添加 1;
- 向顶点 3 和 1 各添加 3。
最终权重为 [5,3,4,0]。该输出合法,因为 a1=a2、a1=a3、a2=a3,且所有所选值均在 1 到 4 之间。
在第二个测试用例中,初始权重为 [0,0,0,0,0]。操作后的权重为 [12,5,6,7,6]。该输出合法,因为 a1=a2、a1=a3、a2=a3,且 a1=a4、a1=a5、a4=a5,同时所有所选值均在 1 到 4 之间。
在第三个测试用例中,初始权重为 [3,4,5,6]。操作后的权重为 [19,16,17,20],且所有最终权重互不相同,这意味着任意两个相邻顶点的权重均不相等。
输入解题思路,AI测评打分。不知道怎么写?