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 burningburning desiredesire, GodFlyGodFly began his journey to chase after a junior girl.

Problem Description

We abstract the campus as an undirected connected graph with nn vertices, numbered 1,2,3,...,n1,2,3,...,n. Let the vertices that GodFlyGodFly passes through be represented as a path set A={a1,a2,a3,...,am}A=\left\{a_1,a_2,a_3,...,a_m\right\}, meaning that he passes through vertices numbered a1a_1, a2a_2, …, ama_m in order. Since the elements of a set are distinct, this means that GodFlyGodFly cannot pass through the same vertex repeatedly.

Now GodFlyGodFly wants to walk from vertex 11 to vertex nn, but his leg problem causes him a lot of trouble. Define that GodFlyGodFly has passed through mm vertices, is currently at vertex ama_m, and the path set is A={a1,a2,a3...,am1}A=\left\{a_1,a_2,a_3...,a_{m-1}\right\} (before adding the new vertex ama_m). Then his total stamina cost is wm=(wm1+amsum(A))w_m=(w_{m-1}+a_m*sum(A))%22, where wm1w_{m-1} is the stamina cost of the previous path set. For the set AA, sum(A)=a1+a2+...+am1sum(A)=a_1+a_2+...+a_{m-1}.

When w=0w=0, we say GodFlyGodFly is in the “滑基态” ("huaji state"). Otherwise, when w=1w=1, we say GodFlyGodFly is in the “对偶态” ("dual state"). Now GodFlyGodFly wants to know the number of ways such that after he reaches vertex nn, 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 1926081719260817. 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 nn and kk, representing the number of vertices and the number of edges.

The next kk lines each contain two integers uu and vv, indicating that there is an edge between vertex uu and vertex vv.

The last line of the input contains an integer cc. c=0c=0 means you need the number of ways for the huaji state, and c=1c=1 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 3030% of the testdata, n<=10n<=10, k<=45k<=45, with no multiple edges or self-loops.

For 6060% of the testdata, n<=15n<=15, k<=300k<=300.

For 8080% of the testdata, n<=15n<=15, k<=100000k<=100000.

For 100100% of the testdata, n<=18n<=18, k<=100000k<=100000.

Sample Explanation

As shown in the figure, initially at vertex 11, the path set is {1}\left\{1\right\}, and the cost is 00.

If you go from vertex 11 to vertex 22 and then to vertex 33: when arriving at vertex 22, the cost is (0+2sum({1}))(0+2*sum(\left\{1\right\}))%2=212=2*1%2=02=0, and then add 22 into the path set, so the path set becomes {1,2}\left\{1,2\right\}. When arriving at vertex 33, since the previous cost is 00, the cost is (0+3sum({1,2}))(0+3*sum(\left\{1,2\right\}))%2=3(1+2)2=3*(1+2)%2=12=1.

If you go directly from vertex 11 to vertex 33, then the cost is (0+3sum({1}))(0+3*sum(\left\{1\right\}))%2=312=3*1%2=12=1.

Therefore, the number of ways that end at vertex 33 with cost 11 is 22.

Hint

The time limit for this problem is 3s3s, and you may enable O2O_2 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