#abc319g. G - Counting Shortest Paths

G - Counting Shortest Paths

Score : 575575 points

问题描述

我们将对一个包含 NN 个顶点的完全无向图 GG 执行以下操作:

对于每个 i=1,2,,Mi = 1, 2, \ldots, M,删除连接顶点 uiu_iviv_i 的无向边。

确定在执行该操作后,在图 GG 中是否存在从顶点 11 到顶点 NN 的路径。如果存在,请找出从顶点 11 到顶点 NN 的最短路径的数量,取模 998244353998244353 后的结果。

这里,从顶点 11 到顶点 NN 的最短路径是指包含最少边数的从顶点 11 到顶点 NN 的路径。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We will perform the following operation on a complete undirected graph GG with NN vertices.

For each i=1,2,,Mi = 1, 2, \ldots, M, delete the undirected edge connecting vertices uiu_i and viv_i.

Determine if there is a path from vertex 11 to vertex NN in GG after the operation. If there is, find the number, modulo 998244353998244353, of shortest paths from vertex 11 to vertex NN.

Here, a shortest path from vertex 11 to vertex NN is a path from vertex 11 to vertex NN that contains the minimum number of edges.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • $0 \leq M \leq \min\lbrace 2 \times 10^5, N(N-1)/2 \rbrace$
  • 1ui,viN1 \leq u_i, v_i \leq N
  • uiviu_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:

NN MM

u1u_1 v1v_1

u2u_2 v2v_2

\vdots

uMu_M vMv_M

Output

If there is no path from vertex 11 to vertex NN in GG after the operation, print -1. If there is, print the number, modulo 998244353998244353, of shortest paths from vertex 11 to vertex NN.

Sample Input 1

6 7
4 3
1 3
2 4
1 6
4 6
5 1
6 2

Sample Output 1

3

In GG after the operation, the shortest paths from vertex 11 to vertex NN are the following three, each containing three edges.

  • vertex 11 \rightarrow vertex 22 \rightarrow vertex 33 \rightarrow vertex 66
  • vertex 11 \rightarrow vertex 22 \rightarrow vertex 55 \rightarrow vertex 66
  • vertex 11 \rightarrow vertex 44 \rightarrow vertex 55 \rightarrow vertex 66

Sample Input 2

4 6
1 2
1 3
1 4
2 3
2 4
3 4

Sample Output 2

-1

GG has no edges after the operation. There is no path from vertex 11 to vertex NN, so print -1.

update @ 2024/3/10 09:08:19