Jumbled Trees

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

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 x_ix\_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 u_iu\_i, v_iv\_i, x_ix\_i each --- the two endpoints of the ii-th edge and the target value of that edge's counter (1u_i,v_in1 \le u\_i, v\_i \le n; 0x_i<p0 \le x\_i < p; u_iv_iu\_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.

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 e_1e\_1, e_2e\_2, \ldots, e_n1e\_{n - 1} (1e_im1 \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.