I love the "Wario Land" game series, so I'd like to make a very difficult (really!!!) problem about it :) A big thank you to Erjin Zhou for the idea and reference code. And a small thank you to Wenbin Tang for reminding me that "Rujia Liu" also contains the letter L!
Suppose there are places at the very beginning of Wario Land. The land is almost abandoned, so there are no roads at all! You will be given operations. Execute them one by one and output the results.
The input contains several test cases. In each test case, the first line contains three integers , , (1 \leq n \leq 50\,000, 1 \leq m \leq 100\,000, 2 \leq k \leq 33\,333). The places are numbered from to . The second line contains integers V_i (1 \leq V_i \leq k), the initial treasure values of each place. Each of the next lines contains an operation. For each operation, 1 \leq x, y \leq n, 1 \leq v \leq k. The input is terminated by end-of-file (EOF). The input file size does not exceed MB.
For each type- operation, output the number of places and the product of their treasure values modulo . If there is no path between and , or every place along the path has treasure value , output a single 0 (not 0 0 or 0 1).
Obfuscation
To prevent you from preprocessing the operations, we apply the following obfuscation scheme:
Each type- operation becomes x+d y+d Each type- operation becomes x+d v+d Each type- operation becomes x+d y+d v+d
Here, is the last integer you output before processing this operation. If you haven't output anything yet, d=0.
After obfuscation, the sample input would look like this:
4 8 39 2 3 4 5 1 1 2 3 2 3 5 1 1 3 3 2 3 5 1 25 28 3 27 28 28 3 11 12 13 3 4 5 2
This is the actual input your program will read.
Ejemplo 1