#abc319g. G - Counting Shortest Paths
G - Counting Shortest Paths
Score : points
问题描述
我们将对一个包含 个顶点的完全无向图 执行以下操作:
对于每个 ,删除连接顶点 和 的无向边。
确定在执行该操作后,在图 中是否存在从顶点 到顶点 的路径。如果存在,请找出从顶点 到顶点 的最短路径的数量,取模 后的结果。
这里,从顶点 到顶点 的最短路径是指包含最少边数的从顶点 到顶点 的路径。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We will perform the following operation on a complete undirected graph with vertices.
For each , delete the undirected edge connecting vertices and .
Determine if there is a path from vertex to vertex in after the operation. If there is, find the number, modulo , of shortest paths from vertex to vertex .
Here, a shortest path from vertex to vertex is a path from vertex to vertex that contains the minimum number of edges.
Constraints
- $0 \leq M \leq \min\lbrace 2 \times 10^5, N(N-1)/2 \rbrace$
- $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:
Output
If there is no path from vertex to vertex in after the operation, print -1
. If there is, print the number, modulo , of shortest paths from vertex to vertex .
Sample Input 1
6 7
4 3
1 3
2 4
1 6
4 6
5 1
6 2
Sample Output 1
3
In after the operation, the shortest paths from vertex to vertex are the following three, each containing three edges.
- vertex vertex vertex vertex
- vertex vertex vertex vertex
- vertex vertex vertex vertex
Sample Input 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
Sample Output 2
-1
has no edges after the operation. There is no path from vertex to vertex , so print -1
.
update @ 2024/3/10 09:08:19