#P12799. [NERC 2022] Jumbled Trees

    ID: 12579 Type: RemoteJudge 3000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>2022Special JudgeICPCNERC/NEERC

[NERC 2022] Jumbled Trees

题目描述

You are given an undirected connected graph with nn vertices and mm edges. Each edge has an associated counter, initially equal to 00. In one operation, you can choose an arbitrary spanning tree and add any value vv to all edges of this spanning tree.

Determine if it's possible to make every counter equal to its target value xix_i modulo prime pp, and provide a sequence of operations that achieves it.

输入格式

The first line contains three integers nn, mm, and pp --- the number of vertices, the number of edges, and the prime modulus (1n5001 \le n \le 500; 1m10001 \le m \le 1000; 2p1092 \le p \le 10^9, pp is prime).

Next mm lines contain three integers uiu_i, viv_i, xix_i each --- the two endpoints of the ii-th edge and the target value of that edge's counter (1ui,vin1 \le u_i, v_i \le n; 0xi<p0 \le x_i < p; uiviu_i \neq v_i).

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 1\tt{-1}.

Otherwise, print tt --- the number of operations, followed by tt lines, describing the sequence of operations. Each line starts with integer vv (0v<p0 \le v < p) --- the counter increment for this operation. Then, in the same line, followed by n1n - 1 integers e1e_1, e2e_2, \ldots en1e_{n - 1} (1eim1 \le e_i \le m) --- the edges of the spanning tree.

The number of operations tt should not exceed 2m2m. You don't need to minimize tt. Any correct answer within the 2m2m 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