rt.CE了,因为已经取地址了不能调用,怎么改才能逃脱 CE?
/*
对于每次送货:
1. BFS 从 (1,1) 到最近的商铺
2. 再从商铺 BFS 到顾客家中
*/
# include <bits/stdc++.h>
# define N 210
using namespace std;
int n, m, gktot, ans, ANS, x = 1, y = 1, X, Y;
int mp[N][N];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
struct Edge {
int xt, yt;
} gk[N * N];
bool vis[N][N];
void DFS1 (int &x, int &y, int &ans) {
if (!mp[x][y]) return ;
vis[x][y] = 1;
for (int i = 0; i < 4; i ++) {
int fx = x + dx[i], fy = y + dy[i];
if (fx < 0 || fx > n || fy < 0 || fy > n || vis[fx][fy]) continue;
DFS1(fx, fy, ans + 1);
}
}
void DFS2 (int &x, int &y, int &ans) {
if (x == X && y == Y) return ;
vis[x][y] = 1;
for (int i = 0; i < 4; i ++) {
int fx = x + dx[i], fy = y + dy[i];
if (fx < 0 || fx > n || fy < 0 || fy > n || vis[fx][fy]) continue;
DFS2(fx, fy, ans + 1);
}
}
int main () {
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= m; j ++) {
cin >> mp[i][j];
if (!mp[i][j]) gk[++ gktot] = {i, j};
}
}
ANS = 0;
for (int i = 1; i <= gktot; i ++) {
X = gk[i].xt, Y = gk[i].yt;
ans = 0;
memset (vis, 0, sizeof(vis));
DFS1 (x, y, ans);
memset (vis, 0, sizeof(vis));
DFS2 (x, y, ans);
ANS += ans;
}
cout << ANS;
return 0;
}