6857.Graph Paths I

Time Limit: 1s Memory Limit: 512MB

Consider a directed graph that has $n$ nodes and $m$ edges. Your task is to count the number of paths from node $1$ to node $n$ with exactly $k$ edges.

Input Format(From the terminal/stdin)

The first input line contains three integers $n$ , $m$ and $k$ : the number of nodes and edges, and the length of the path. The nodes are numbered $1,2,\dots,n$ .

Then, there are $m$ lines describing the edges. Each line contains two integers $a$ and $b$ : there is an edge from node $a$ to node $b$ .

  • $1 \le n \le 100$
  • $1 \le m \le n(n-1)$
  • $1 \le k \le 10^9$
  • $1 \le a,b \le n$

Output Format(To the terminal/stdout)

Print the number of paths modulo $10^9+7$ .

Sample Input

Copy
3 4 8
1 2
2 3
3 1
3 2
 · · \n
 · \n
 · \n
 · \n
 · \n

Sample Output

Copy
2
 \n

The paths are $1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 3$ and $1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 3$ .

Source: CSES, Mathematics, 1723

Submit

请先 登录

© 2025 FAQs