AtCoder Beginner Contest 319
G
Counting Shortest Paths
AtCoder
⌀ 2185
原题
翻译中…

Problem Statement

翻译中…

We will perform the following operation on a complete undirected graph $G$ with $N$ vertices.

翻译中…

For each $i = 1, 2, \ldots, M$, delete the undirected edge connecting vertices $u_i$ and $v_i$.

翻译中…

Determine if there is a path from vertex $1$ to vertex $N$ in $G$ after the operation. If there is, find the number, modulo $998244353$, of shortest paths from vertex $1$ to vertex $N$.

翻译中…

Here, a shortest path from vertex $1$ to vertex $N$ is a path from vertex $1$ to vertex $N$ that contains the minimum number of edges.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 2 \times 10^5$
  • $0 \leq M \leq \min\lbrace 2 \times 10^5, N(N-1)/2 \rbrace$
  • $1 \leq u_i, v_i \leq N$
  • $u_i \neq v_i$
  • $i \neq j \implies \lbrace u_i, v_i \rbrace \neq \lbrace u_j, v_j \rbrace$
  • All input values are integers.
翻译中…

Input

翻译中…

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

翻译中…

N M
u_1 v_1
u_2 v_2
\vdots
u_M v_M

翻译中…

Output

翻译中…

If there is no path from vertex $1$ to vertex $N$ in $G$ after the operation, print -1. If there is, print the number, modulo $998244353$, of shortest paths from vertex $1$ to vertex $N$.

翻译中…

样例

Input #1
6 7
4 3
1 3
2 4
1 6
4 6
5 1
6 2
Output #1
3
In $G$ after the operation, the shortest paths from vertex $1$ to vertex $N$ are the following three, each containing three edges. - vertex $1$ $\rightarrow$ vertex $2$ $\rightarrow$ vertex $3$ $\rightarrow$ vertex $6$ - vertex $1$ $\rightarrow$ vertex $2$ $\rightarrow$ vertex $5$ $\rightarrow$ vertex $6$ - vertex $1$ $\rightarrow$ vertex $4$ $\rightarrow$ vertex $5$ $\rightarrow$ vertex $6$
Input #2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Output #2
-1
$G$ has no edges after the operation. There is no path from vertex $1$ to vertex $N$, so print `-1`.
题目信息
题号
abc319_g
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。