#P2579. [ZJOI2005] 沼泽鳄鱼
[ZJOI2005] 沼泽鳄鱼
Description
The Pantanal wetland is known as the largest wetland in the world. It is located in the southern part of Mato Grosso do Sul in central Brazil. Every rainy season, waves sparkle and life flourishes here, attracting many tourists.
To make the visit more interesting, several stone piers and stone bridges were built in the middle of a pond. Each stone bridge connects two stone piers, and between any two stone piers there is at most one bridge. This attraction has never been opened to the public because there are many dangerous piranhas in the pond.
Mr. Doudou loves adventure. As soon as he heard the news, he hurried to the pond, wanting to be the first person to walk on the bridges. Although he is adventurous, he does not want to risk his life, so he conducted careful field research and reached some startling conclusions: the routes of the piranhas are periodic, and the period can only be , , or units of time. In each unit of time, a piranha can swim from one stone pier to another. Upon arriving at a stone pier, if there is someone on it, it will attack; otherwise, it continues its periodic movement. If it is not at a stone pier, it will not attack.
With advanced instruments, Doudou quickly figured out all the movement patterns of the piranhas, and he started planning his own route. In each unit of time, he can only walk along a bridge from one stone pier to another, and he is not allowed to stay on any pier without moving, because standing still also involves other dangers. If Doudou and a piranha arrive at the same stone pier at the same time, he will be attacked by the piranha, which he certainly wants to avoid.
Doudou has selected two stone piers and . He wants to start from and be standing on after exactly units of time. Assume that stone piers may be revisited (including and ). He asks you to compute how many such routes exist (of course without being attacked by any piranha).
Input Format
The input consists of lines.
The first line contains five positive integers , representing the number of stone piers, the number of stone bridges, the indices of and , and the required units of time for a route, respectively. Stone piers are numbered from to .
Lines to give the information about the stone bridges. Each of these lines contains two integers and , , indicating that the bridge connects the piers numbered and .
Line contains an integer , the number of piranhas.
Lines to each describe one piranha. The first integer is , with or , indicating the period of the piranha’s movement. Then follow numbers describing the route within one period.
- If , the next numbers are and : the piranha moves from to , from to , .
- If , the next numbers are and : the piranha moves from to , from to , from to , .
- If , the next numbers are and : the piranha moves from to , from to , from to , from to , .
At the time Doudou starts, all piranhas are at position on their routes. Rest assured, this position will not be the pier.
Output Format
Output the number of routes. Since this number may be large, output the remainder when it is divided by .
6 8 1 5 3
0 2
2 1
1 0
0 5
5 1
1 4
4 3
3 5
1
3 0 5 1
2
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号