#P17427. [ICPC 2018 Xuzhou R] Rikka with An Unnamed Temple
[ICPC 2018 Xuzhou R] Rikka with An Unnamed Temple
Problem Description
Rikka discovered an unnamed ancient temple together with its internal map by accident. The temple contains separated rooms. Several one-way roads connect these rooms and form a directed acyclic graph.
When a visitor enters the temple, she will appear in the first room. she can find the exit of the temple in the -th room. Notice that she probably cannot arrive all rooms from the entrance and meanwhile, she may not have the chance to escape the temple from some room inside.
All rooms have some treasures. The weight of the treasure stored in the -th room is , and its value is . A visitor, when she arrives at the exit, is allowed to leave the temple if the remainder of the total weight of treasures she has picked divided by is equal to where and are fixed integers.
Besides, a guardian is standing in a room and protecting the treasure, but no one knows where she is. To prevent being attacked, visitors should not step into the room of the guardian at any time.
Now Rikka decides to visit the unnamed temple. She will select a path from the entrance to the exit, picking treasures in all rooms she will pass through. She wants you to calculate, for each index from to , what the maximum total value she can obtain is and in how many ways she could achieve that, in case the guardian is standing in the -th room.
Input Format
The input contains several test cases, and the first line contains a single integer (), the number of test cases.
For each test case, the first line contains two integers (), the number of rooms, and (), the number of one-way roads.
The following lines describe all rooms. The -th of them contains two integers and ().
Then following lines describe all roads. The -th of them contains two integers and () which describes a one-way road from the -th room to the -th room.
The last line contains two integers and () which are the coefficients for the condition to leave the temple.
The input guarantees that all roads in a single test case are distinct, the sum of in all test cases is at most , and the sum of in all test cases is at most .
Output Format
For each test case, output lines. In the -th line, we consider the case when the guardian is standing in the -th room. If there is no valid path for Rikka to visit the temple from the entrance to the exit, output in this line. Otherwise, output two space-separated integers in this line, where the first one is the maximum total value she can obtain, and the second one is the number of different paths she can select to achieve the best result. The first number should be outputted in exact form, while the second one should be outputted in modulo .
1
4 5
1 2
2 3
3 4
4 2
1 2
1 3
2 4
3 4
1 4
5 3
-1
8 1
-1
-1