luogu#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 before resetting. We also denote the initial state as another weighted undirected complete graph . Both and have exactly vertices, and these vertices are labeled from to .
To reset graph to Yae can perform the following operation any number of times:
- First select four distinct vertices , , , and an integer . Note that she can select a different set of , , , and each time.
- Let be the edge between vertices and . Increase the weight of , and by and also decrease the weight of , and by .
Please help Yae determine whether she can change graph to graph . 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 () indicating the number of vertices in graph and .
For the following lines, the -th line contains integers () where indicates the weight of the edge connecting vertices and in graph .
For the following lines, the -th line contains integers () where indicates the weight of the edge connecting vertices and in graph .
输出格式
If Yae cannot change to , output -1
.
Otherwise first output an integer () in one line indicating the number of operations Yae needs.
For the following lines, output five integers , , , and in the -th line separated by a space, indicating that for the -th operation Yae choose vertices , , , and integer . Note that , , , must be distinct and .
It can be proved that if graph can be changed to graph there exists a solution with no more than operations.
Note that you don't have to minimize . If there are multiple solutions, output any of them.
题目大意
给定一个 个点的带权完全图 ,现在你可以对这个图做至多 次如下操作,使其变成另一张带权完全图 :
- 选取四个点 与权值 ,使得边 加上 ,边 减去 。
构造一组方案或判断无解。
,边权在 之间。
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