CF1650G.Counting Shortcuts

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given an undirected connected graph with nn vertices and mm edges. The graph contains no loops (edges from a vertex to itself) and multiple edges (i.e. no more than one edge between each pair of vertices). The vertices of the graph are numbered from 11 to nn.

Find the number of paths from a vertex ss to tt whose length differs from the shortest path from ss to tt by no more than 11. It is necessary to consider all suitable paths, even if they pass through the same vertex or edge more than once (i.e. they are not simple).

Graph consisting of 66 of vertices and 88 of edges

For example, let n=6n = 6, m=8m = 8, s=6s = 6 and t=1t = 1, and let the graph look like the figure above. Then the length of the shortest path from ss to tt is 11. Consider all paths whose length is at most 1+1=21 + 1 = 2.

  • 6→16 \rightarrow 1. The length of the path is 11.
  • 6→4→16 \rightarrow 4 \rightarrow 1. Path length is 22.
  • 6→2→16 \rightarrow 2 \rightarrow 1. Path length is 22.
  • 6→5→16 \rightarrow 5 \rightarrow 1. Path length is 22.

There is a total of 44 of matching paths.

给定一个包含 nn 个顶点和 mm 条边的无向连通图。该图不含自环(即不存在从一个顶点指向其自身的边)和重边(即任意两个顶点之间至多只有一条边)。图中顶点编号为 11 到 nn。

求从顶点 ss 到顶点 tt 的路径数目,使得这些路径的长度与 ss 到 tt 的最短路径长度之差不超过 11。需考虑所有满足条件的路径,即使它们多次经过同一顶点或同一条边(即这些路径不一定是简单路径)。

包含 66 个顶点和 88 条边的图

例如,设 n=6n = 6,m=8m = 8,s=6s = 6,t=1t = 1,且图如上图所示。则 ss 到 tt 的最短路径长度为 11。现考虑所有长度不超过 1+1=21 + 1 = 2 的路径:

  • 6→16 \rightarrow 1:路径长度为 11。
  • 6→4→16 \rightarrow 4 \rightarrow 1:路径长度为 22。
  • 6→2→16 \rightarrow 2 \rightarrow 1:路径长度为 22。
  • 6→5→16 \rightarrow 5 \rightarrow 1:路径长度为 22。

共有 44 条满足条件的路径。

输入格式

The first line of test contains the number tt (1≤t≤1041 \le t \le 10^4) —the number of test cases in the test.

Before each test case, there is a blank line.

The first line of test case contains two numbers n,mn, m (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 1≤m≤2⋅1051 \le m \le 2 \cdot 10^5) —the number of vertices and edges in the graph.

The second line contains two numbers ss and tt (1≤s,t≤n1 \le s, t \le n, s≠ts \neq t) —the numbers of the start and end vertices of the path.

The following mm lines contain descriptions of edges: the iith line contains two integers uiu_i, viv_i (1≤ui,vi≤n1 \le u_i,v_i \le n) — the numbers of vertices that connect the iith edge. It is guaranteed that the graph is connected and does not contain loops and multiple edges.

It is guaranteed that the sum of values nn on all test cases of input data does not exceed 2⋅1052 \cdot 10^5. Similarly, it is guaranteed that the sum of values mm on all test cases of input data does not exceed 2⋅1052 \cdot 10^5.

测试的第一行包含一个数字 tt(1≤t≤1041 \le t \le 10^4)——测试数据中测试用例的数量。

每个测试用例前有一空行。

每个测试用例的第一行包含两个数字 n,mn, m(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤m≤2⋅1051 \le m \le 2 \cdot 10^5)——图中顶点数和边数。

第二行包含两个数字 ss 和 tt(1≤s,t≤n1 \le s, t \le n,s≠ts \neq t)——路径的起点和终点顶点编号。

接下来的 mm 行描述各条边:第 ii 行包含两个整数 uiu_i、viv_i(1≤ui,vi≤n1 \le u_i,v_i \le n)——表示第 ii 条边所连接的两个顶点编号。保证该图是连通的,且不含自环和重边。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5;同理,保证所有测试用例中 mm 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single number — the number of paths from ss to tt such that their length differs from the length of the shortest path by no more than 11.

Since this number may be too large, output it modulo 109+710^9 + 7.

对于每个测试用例,输出一个整数——即从 ss 到 tt 的路径数量,这些路径的长度与最短路径长度之差不超过 11。

由于该数值可能过大,请对 109+710^9 + 7 取模后输出。

输入输出样例

  • 输入#1

    4
    
    4 4
    1 4
    1 2
    3 4
    2 3
    2 4
    
    6 8
    6 1
    1 4
    1 6
    1 5
    1 2
    5 6
    4 6
    6 3
    2 6
    
    5 6
    1 3
    3 5
    5 4
    3 1
    4 2
    2 1
    1 4
    
    8 18
    5 1
    2 1
    3 1
    4 2
    5 2
    6 5
    7 3
    8 4
    6 4
    8 7
    1 4
    4 7
    1 6
    6 7
    3 8
    8 5
    4 5
    4 3
    8 2

    输出#1

    2
    4
    1
    11

输入解题思路,AI测评打分。不知道怎么写?

首页