#abc372f. F - Teleporting Takahashi 2
F - Teleporting Takahashi 2
Score : points
问题陈述
存在一个简单的有向图 ,包含 个顶点和 条边。顶点编号从 到 ,边编号从 到 。
边 从顶点 指向顶点 。(这里,顶点 被视为顶点 。)
边 从顶点 指向顶点 。
高桥位于顶点 。在每个顶点,他可以移动到从当前顶点有出边指向的任何顶点。
计算他恰好移动 次的方式数量。
即,找出满足以下所有三个条件的整数序列 的长度为 的数量:
- 对于 ,有 。
- 。
- 对于 ,存在一条从顶点 指向顶点 的有向边。
由于这个数字可能非常大,请打印出模 的结果。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a simple directed graph with vertices and edges. The vertices are numbered to , and the edges are numbered to .
Edge goes from vertex to vertex . (Here, vertex is considered as vertex .)
Edge goes from vertex to vertex .
Takahashi is at vertex . At each vertex, he can move to any vertex to which there is an outgoing edge from the current vertex.
Compute the number of ways he can move exactly times.
That is, find the number of integer sequences of length satisfying all of the following three conditions:
- for .
- .
- There is a directed edge from vertex to vertex for .
Since this number can be very large, print it modulo .
Constraints
- ,
- All of the directed edges are distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the count modulo .
Sample Input 1
6 2 5
1 4
2 5
Sample Output 1
5
The above figure represents the graph . There are five ways for Takahashi to move:
- Vertex Vertex Vertex Vertex Vertex Vertex
- Vertex Vertex Vertex Vertex Vertex Vertex
- Vertex Vertex Vertex Vertex Vertex Vertex
- Vertex Vertex Vertex Vertex Vertex Vertex
- Vertex Vertex Vertex Vertex Vertex Vertex
Sample Input 2
10 0 200000
Sample Output 2
1
Sample Input 3
199 10 1326
122 39
142 49
164 119
197 127
188 145
69 80
6 120
24 160
18 154
185 27
Sample Output 3
451022766