注意记录每个点是被边缘哪个点更新时,只应该记录最短路而不应该将次短路的源点覆盖。
可以参考下面的小数据:
5
10 9
#..##.#.#
.##.#.#.#
...#.V#..
.#.##.###
.##.#...#
......#..
...#.#..#
####...##
#.#..##.#
#.#.##..#
3 5
#V#.#
#...#
##.##
5 6
#V##.#
#..##.
#...##
###.#.
#....#
5 7
#.#.###
.#..V##
..#...#
#.###.#
#####.#
7 5
###.#
#.V.#
##..#
#.#.#
##..#
...##
#####
输出
39
2
7
7
3
如果您需要对拍,可以直接使用下面的数据生成器:
#include <bits/stdc++.h>
using namespace std;
mt19937 rd(time(0));
int n,m;
bool ck(int i,int j){return (i == 1 && j == 1) || (i == 1 && j == m) || (i == n && j == 1) || (i == n && j == m);}
signed main(signed argc, char* argv[]){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
srand(atoi(argv[1]));
cout << 10000 << "\n";//t = 10000
for(int t = 1;t <= 10000;t ++){
n = rd() % 5 + 3,m = rd() % 5 + 3;//n,m 3~7
cout << n << " " << m << "\n";
int px = rd() % n + 1,py = rd() % m + 1;
while(ck(px,py)) px = rd() % n + 1,py = rd() % m + 1;
for(int i = 1;i <= n;i ++,cout << "\n"){
for(int j = 1;j <= m;j ++){
if(ck(i,j)) cout << "#";
else if(px == i && py == j) cout << "V";
else cout << "#."[rd() & 1];
}
}}
return 0;
}