#P9841. [ICPC2021 Nanjing R] Puzzle in Inazuma

[ICPC2021 Nanjing R] Puzzle in Inazuma

题目描述

Every traveler knows that they'll be rewarded with a treasure box after solving the puzzles in Inazuma, but few know that these puzzles are designed by Yae Miko, the Guuji of the Grand Narukami Shrine, to test whether the traveler is strong enough to save her friend Raiden Shogun and people of Inazuma.

After a traveler passes the test Yae will have to reset the puzzles to the initial state. But this time she has some troubles and even doubts that whether some of them are already broken.

Yae's puzzle can be considered as a weighted undirected complete graph GG before resetting. We also denote the initial state as another weighted undirected complete graph HH. Both GG and HH have exactly nn vertices, and these vertices are labeled from 11 to nn.

To reset graph GG to HH Yae can perform the following operation any number of times:

  • First select four distinct vertices aa, bb, cc, dd and an integer xx. Note that she can select a different set of aa, bb, cc, dd and xx each time.
  • Let (i,j)(i, j) be the edge between vertices ii and jj. Increase the weight of (a,b)(a, b), (a,c)(a, c) and (a,d)(a, d) by xx and also decrease the weight of (b,c)(b, c), (b,d)(b, d) and (c,d)(c, d) by xx.

Please help Yae determine whether she can change graph GG to graph HH. If yes you also shall tell her the detailed steps.

输入格式

There is only one test case in each test file.

The first line of the input contains an integer nn (4n1004 \leq n \leq 100) indicating the number of vertices in graph GG and HH.

For the following (n1)(n - 1) lines, the ii-th line contains (ni)(n - i) integers wi,i+1,wi,i+2,,wi,nw_{i, i + 1}, w_{i, i + 2}, \cdots, w_{i, n} (100wi,j100-100 \le w_{i, j} \le 100) where wi,jw_{i, j} indicates the weight of the edge connecting vertices ii and jj in graph GG.

For the following (n1)(n - 1) lines, the ii-th line contains (ni)(n - i) integers vi,i+1,vi,i+2,,vi,nv_{i, i + 1}, v_{i, i + 2}, \cdots, v_{i, n} (100vi,j100-100 \le v_{i, j} \le 100) where vi,jv_{i, j} indicates the weight of the edge connecting vertices ii and jj in graph HH.

输出格式

If Yae cannot change GG to HH, output -1.

Otherwise first output an integer mm (0m1050 \le m \le 10^5) in one line indicating the number of operations Yae needs.

For the following mm lines, output five integers aia_i, bib_i, cic_i, did_i and xix_i in the ii-th line separated by a space, indicating that for the ii-th operation Yae choose vertices aia_i, bib_i, cic_i, did_i and integer xix_i. Note that aia_i, bib_i, cic_i, did_i must be distinct and 109xi109-10^9 \le x_i \le 10^9.

It can be proved that if graph GG can be changed to graph HH there exists a solution with no more than 10510^5 operations.

Note that you don't have to minimize mm. If there are multiple solutions, output any of them.

题目大意

给定一个 nn 个点的带权完全图 GG,现在你可以对这个图做至多 10510^5 次如下操作,使其变成另一张带权完全图 HH

  • 选取四个点 a,b,c,da,b,c,d 与权值 xx,使得边 (a,b),(a,c),(a,d)(a,b),(a,c),(a,d) 加上 xx,边 (b,c),(b,d),(c,d)(b,c),(b,d),(c,d) 减去 xx

构造一组方案或判断无解。
4n1004\le n\le 100,边权在 100100-100\sim 100 之间。

4
0 1 1
0 0
1
1 0 0
1 1
0

1
2 1 3 4 1

4
3 3 3
0 0
0
0 0 0
3 3
3

1
1 2 3 4 -3

5
-12 15 -12 1
37 14 7
7 9
-11
12 5 1 13
-1 -4 -7
-5 -9
18

-1