103725: [Atcoder]ABC372 F - Teleporting Takahashi 2

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:19 Solved:0

Description

Score : $525$ points

Problem Statement

There is a simple directed graph $G$ with $N$ vertices and $N+M$ edges. The vertices are numbered $1$ to $N$, and the edges are numbered $1$ to $N+M$.

Edge $i$ goes from vertex $i$ to vertex $i+1$. (Here, vertex $N+1$ is considered as vertex $1$.)
Edge $N+i$ $(1 \leq i \leq M)$ goes from vertex $X_i$ to vertex $Y_i$.

Takahashi is at vertex $1$. 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 $K$ times.

That is, find the number of integer sequences $(v_0, v_1, \dots, v_K)$ of length $K+1$ satisfying all of the following three conditions:

  • $1 \leq v_i \leq N$ for $i = 0, 1, \dots, K$.
  • $v_0 = 1$.
  • There is a directed edge from vertex $v_{i-1}$ to vertex $v_i$ for $i = 1, 2, \ldots, K$.

Since this number can be very large, print it modulo $998244353$.

Constraints

  • $2 \leq N \leq 2 \times 10^5$
  • $0 \leq M \leq 50$
  • $1 \leq K \leq 2 \times 10^5$
  • $1 \leq X_i, Y_i \leq N$, $X_i \neq Y_i$
  • All of the $N+M$ directed edges are distinct.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

$N$ $M$ $K$
$X_1$ $Y_1$
$X_2$ $Y_2$
$\vdots$
$X_M$ $Y_M$

Output

Print the count modulo $998244353$.


Sample Input 1

6 2 5
1 4
2 5

Sample Output 1

5

sample1

The above figure represents the graph $G$. There are five ways for Takahashi to move:

  • Vertex $1 \to$ Vertex $2 \to$ Vertex $3 \to$ Vertex $4 \to$ Vertex $5 \to$ Vertex $6$
  • Vertex $1 \to$ Vertex $2 \to$ Vertex $5 \to$ Vertex $6 \to$ Vertex $1 \to$ Vertex $2$
  • Vertex $1 \to$ Vertex $2 \to$ Vertex $5 \to$ Vertex $6 \to$ Vertex $1 \to$ Vertex $4$
  • Vertex $1 \to$ Vertex $4 \to$ Vertex $5 \to$ Vertex $6 \to$ Vertex $1 \to$ Vertex $2$
  • Vertex $1 \to$ Vertex $4 \to$ Vertex $5 \to$ Vertex $6 \to$ Vertex $1 \to$ Vertex $4$

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

Output

得分:525分

问题陈述

有一个简单的有向图$G$,有$N$个顶点和$N+M$条边。顶点编号为$1$到$N$,边编号为$1$到$N+M$。

边$i$从顶点$i$到顶点$i+1$。(这里的顶点$N+1$被认为是顶点$1$。)
边$N+i$ $(1 \leq i \leq M)$从顶点$X_i$到顶点$Y_i$。

高桥位于顶点$1$。在每个顶点,他可以移动到当前顶点有任何出边的任何顶点。

计算他恰好移动$K$次的方案数。

即,找到长度为$K+1$的整数序列$(v_0, v_1, \dots, v_K)$,满足以下三个条件:

  • $1 \leq v_i \leq N$ 对于$i = 0, 1, \dots, K$。
  • $v_0 = 1$。
  • 对于$i = 1, 2, \ldots, K$,存在从顶点$v_{i-1}$到顶点$v_i$的有向边。

由于这个数字可能非常大,以$998244353$为模打印它。

约束条件

  • $2 \leq N \leq 2 \times 10^5$
  • $0 \leq M \leq 50$
  • $1 \leq K \leq 2 \times 10^5$
  • $1 \leq X_i, Y_i \leq N$,$X_i \neq Y_i$
  • 所有的$N+M$条有向边都是不同的。
  • 所有输入值都是整数。

输入

输入从标准输入以下格式给出:

$N$ $M$ $K$
$X_1$ $Y_1$
$X_2$ $Y_2$
$\vdots$
$X_M$ $Y_M$

输出

打印计数模$998244353$。


样本输入 1

6 2 5
1 4
2 5

样本输出 1

5

sample1

上面的图形表示了图$G$。高桥有五种移动方式:

  • 顶点$1 \to$ 顶点$2 \to$ 顶点$3 \to$ 顶点$4 \to$ 顶点$5 \to$ 顶点$6$
  • 顶点$1 \to$ 顶点$2 \to$ 顶点$5 \to$ 顶点$6 \to$ 顶点$1 \to$ 顶点$2$
  • 顶点$1 \to$ 顶点$2 \to$ 顶点$5 \to$ 顶点$6 \to$ 顶点$1 \to$ 顶点$4$
  • 顶点$1 \to$ 顶点$4 \to$ 顶点$5 \to$ 顶点$6 \to$ 顶点$1 \to$ 顶点$2$
  • 顶点$1 \to$ 顶点$4 \to$ 顶点$5 \to$ 顶点$6 \to$ 顶点$1 \to$ 顶点$4$

加入题单

上一题 下一题 算法标签: