#P12799. [NERC 2022] Jumbled Trees
[NERC 2022] Jumbled Trees
题目描述
You are given an undirected connected graph with vertices and edges. Each edge has an associated counter, initially equal to . In one operation, you can choose an arbitrary spanning tree and add any value to all edges of this spanning tree.
Determine if it's possible to make every counter equal to its target value modulo prime , and provide a sequence of operations that achieves it.
输入格式
The first line contains three integers , , and --- the number of vertices, the number of edges, and the prime modulus (; ; , is prime).
Next lines contain three integers , , each --- the two endpoints of the -th edge and the target value of that edge's counter (; ; ).
The graph is connected. There are no loops, but there may be multiple edges between the same two vertices.
输出格式
If the target values on counters cannot be achieved, print .
Otherwise, print --- the number of operations, followed by lines, describing the sequence of operations. Each line starts with integer () --- the counter increment for this operation. Then, in the same line, followed by integers , , () --- the edges of the spanning tree.
The number of operations should not exceed . You don't need to minimize . Any correct answer within the bound is accepted. You are allowed to repeat spanning trees.
3 3 101
1 2 30
2 3 40
3 1 50
3
10 1 2
20 1 3
30 2 3
2 2 37
1 2 8
1 2 15
2
8 1
15 2
5 4 5
1 3 1
2 3 2
2 5 3
4 1 4
-1