luogu#P16359. [BalticOI 2026] Tourist's Journey

[BalticOI 2026] Tourist's Journey

Problem Description

A country with nn cities numbered 1,2,,n1,2,\dots,n is connected by mm two-way roads. There are at most 1010 more roads than the number of cities, but it is still possible to travel between any two cities using one or more roads.

A tourist is planning a journey in the country. They have decided the following:

  • The journey will start in city 11 and end in city nn.
  • The journey should consist of exactly kk steps, each traveling one road.
  • It is not allowed to travel back and forth along the same road in two consecutive steps. It is possible, however, to travel the same road multiple times if there are other steps in between.

How many possible journey plans are there, traveling from city 11 to city nn in kk steps? Two plans are different if they go to different cities at any step.

Input Format

The first line contains three integers nn, mm and kk: the number of cities and roads in the country, as well as the number of steps in the tourist's journey.

The following mm lines describe the roads. Each line contains two distinct integers uu and vv, meaning that there is a road between city uu and city vv. There is at most one road between two cities.

Output Format

Print the number of different journey plans. Since the answer may be large, print it modulo 109+710^9+7.

4 5 5
1 2
1 3
2 3
2 4
3 4
4
4 3 4
1 2
2 3
2 4
0

Hint

Explanation 1

The cities and roads of the country are shown in the figure below.

:::align{center} :::

The possible journey plans are:

  • $1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 4$
  • $1 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 3 \rightarrow 4$
  • $1 \rightarrow 2 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 4$
  • $1 \rightarrow 3 \rightarrow 4 \rightarrow 2 \rightarrow 3 \rightarrow 4$

Explanation 2

There is no valid journey plan with 44 steps. Note that the plan $1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 4$ is invalid because it uses the road between cities 22 and 33 in two consecutive steps.

Constraints

  • 2n21052 \le n \le 2 \cdot 10^5
  • n1mn+10n-1 \le m \le n + 10
  • 1k1041 \le k \le 10^4

Scoring

Subtask Constraints Points
1 n,k10n,k \le 10 77
2 n,k100n,k \le 100 88
3 m=n1m=n-1 1111
4 m=n1m=n-1 or m=nm=n 2929
5 n1000n \le 1000 1515
6 No additional constraints 3030