ABC276E RE两个点,求问为何RE
#include <bits/stdc++.h>
#define int long long
using namespace std;
int h, w;
vector<string> s;
struct XY {
int x, y, c;
} st;
queue<XY> q;
map<pair<int, int>, int> mp;
void bfs() {
if(s[st.x-1][st.y] == '.')
q.push({st.x-1, st.y, 1}), mp[{st.x-1, st.y}] = 1;
if(s[st.x+1][st.y] == '.')
q.push({st.x+1, st.y, 2}), mp[{st.x+1, st.y}] = 2;
if(s[st.x][st.y-1] == '.')
q.push({st.x, st.y-1, 3}), mp[{st.x, st.y-1}] = 3;
if(s[st.x][st.y+1] == '.')
q.push({st.x, st.y+1, 4}), mp[{st.x, st.y+1}] = 4;
while(q.size()) {
XY now = q.front();
q.pop();
if(now.x-1 > 0 && s[now.x-1][now.y] == '.') {
if(!mp[{now.x-1, now.y}]) {
mp[{now.x-1, now.y}] = now.c;
q.push({now.x-1, now.y, now.c});
}
else if(mp[{now.x-1, now.y}] != now.c)
printf("Yes"), exit(0);
}
if(now.x+1 <= h && s[now.x+1][now.y] == '.') {
if(!mp[{now.x+1, now.y}]) {
mp[{now.x+1, now.y}] = now.c;
q.push({now.x+1, now.y, now.c});
}
else if(mp[{now.x+1, now.y}] != now.c)
printf("Yes"), exit(0);
}
if(now.y-1 > 0 && s[now.x][now.y-1] == '.') {
if(!mp[{now.x, now.y-1}]) {
mp[{now.x, now.y-1}] = now.c;
q.push({now.x, now.y-1, now.c});
}
else if(mp[{now.x, now.y-1}] != now.c)
printf("Yes"), exit(0);
}
if(now.y+1 <= w && s[now.x][now.y+1] == '.') {
if(!mp[{now.x, now.y+1}]) {
mp[{now.x, now.y+1}] = now.c;
q.push({now.x, now.y+1, now.c});
}
else if(mp[{now.x, now.y+1}] != now.c)
printf("Yes"), exit(0);
}
}
}
signed main() {
scanf("%lld%lld", &h, &w), s.push_back(" ");
for(int i = 1; i <= h; i++) {
string t;
cin >> t;
for(int j = 0; j < t.size(); j++)
if(t[j] == 'S') st = {i, j+1, 0};
t = ' '+t, s.push_back(t);
}
bfs(), printf("No");
return 0;
}