luogu#P4892. GodFly的寻宝之旅
GodFly的寻宝之旅
Background
“Reeds and rushes grow so lush, the white dew turns to frost. The one I long for is on the other side of the water…”
With a , began his journey to chase after a junior girl.
Problem Description
We abstract the campus as an undirected connected graph with vertices, numbered . Let the vertices that passes through be represented as a path set , meaning that he passes through vertices numbered , , …, in order. Since the elements of a set are distinct, this means that cannot pass through the same vertex repeatedly.
Now wants to walk from vertex to vertex , but his leg problem causes him a lot of trouble. Define that has passed through vertices, is currently at vertex , and the path set is (before adding the new vertex ). Then his total stamina cost is %, where is the stamina cost of the previous path set. For the set , .
When , we say is in the “滑基态” ("huaji state"). Otherwise, when , we say is in the “对偶态” ("dual state"). Now wants to know the number of ways such that after he reaches vertex , he is in the huaji state or the dual state. Since this number may be very large, you only need to output the result modulo . Note that two ways are considered different if and only if they have at least one edge traversed differently, rather than having different path sets.
Input Format
The first line contains two integers and , representing the number of vertices and the number of edges.
The next lines each contain two integers and , indicating that there is an edge between vertex and vertex .
The last line of the input contains an integer . means you need the number of ways for the huaji state, and means you need the number of ways for the dual state.
Output Format
One line containing one integer, the number of ways, as described in the statement.
3 3
1 2
2 3
1 3
1
2
10 30
6 3
5 3
6 7
10 9
2 8
7 2
10 6
7 1
9 4
3 9
7 1
2 2
10 6
7 7
2 4
6 8
1 1
6 4
3 9
8 7
6 2
7 2
1 4
5 4
8 6
2 4
7 1
4 2
10 9
1 6
0
1094
Hint
Constraints
For % of the testdata, , , with no multiple edges or self-loops.
For % of the testdata, , .
For % of the testdata, , .
For % of the testdata, , .
Sample Explanation

As shown in the figure, initially at vertex , the path set is , and the cost is .
If you go from vertex to vertex and then to vertex : when arriving at vertex , the cost is %%, and then add into the path set, so the path set becomes . When arriving at vertex , since the previous cost is , the cost is %%.
If you go directly from vertex to vertex , then the cost is %%.
Therefore, the number of ways that end at vertex with cost is .
Hint
The time limit for this problem is , and you may enable optimization, so you do not need to worry too much about constant factors. However, please make sure your algorithm is efficient enough.
Translated by ChatGPT 5