Jumbled Trees#11329

Jumbled Trees

1 second
128 megabytes
Easy

An undirected connected graph with vertices and edges is given. Each edge has a counter, initially equal to . In one operation, you may choose an arbitrary spanning tree and add the same value to all edges of this tree.

Determine whether it is possible to make the counter of each edge equal to its target value x_i modulo a prime number . If it is possible, print a sequence of operations that achieves the desired configuration.

Input

The first line contains three integers , and p~(1 \le n \le 500, 1 \le m \le 1000, 2 \le p \le 10^9) — the number of vertices, the number of edges, and the modulus. It is guaranteed that is a prime number.

The following lines each contain three integers u_i, v_i, x_i~(1 \le u_i, v_i \le n, 0 \le x_i < p, u_i \ne v_i) — the endpoints of the -th edge and its target value.

The graph is connected. It contains no self-loops, but there may be multiple edges between the same pair of vertices.

Output

If it is impossible to reach the target values, print .

Otherwise, print the number of operations , followed by lines describing them. Each line starts with an integer v~(0 \le v < p) — the increment value for this operation. Then follow n - 1 integers e_1, e_2, \dots, e_{n-1}~(1 \le e_i \le m) — the edges that form the chosen spanning tree.

The number of operations must not exceed . You do not need to minimize : any valid solution within this bound will be accepted. It is allowed to use the same spanning tree multiple times.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading