BFS题目
memset(visited, 0, sizeof(visited)); 原本写成memset(visited, 0, sizeof(visited[0][0]*sizeof(visited[0]))); 结果就错了 后续我做傻了 要用第一种memset sizeof就是去那整个内存空间大小

#include<cstring>
#include<queue>
const int N = 1e9 + 7;
using namespace std;
int n,m;
struct Point{
    int x,y;
    Point(int i,int j){
        x=i,y=j;
    }
};
char point[550][550];
int visited[550][550];
int x1,x2,y1,y2;
queue<Point> q;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int main(){
    while(cin >> n>>m){
        for(int i =1;i<=n;i++){
            for(int j =1;j<=m;j++){
                cin >> point[i][j];
                if(point[i][j]=='S')
                {
                    x1=i;
                    y1=j;
                }
                if(point[i][j]=='E')
                {
                    x2=i;
                    y2=j;
                }
            }
        }
        memset(visited, 0, sizeof(visited));
        q.push(Point(x1,y1));
        visited[x1][y1] = 1;
        while(!q.empty()){
            Point p =q.front();
            q.pop();
            for(int i =0;i<4;i++){
                        int dirx = p.x+dx[i];
                        int diry = p.y+dy[i];
                        if(dirx >=1&&dirx<=n&&diry>=1&&diry<=m
                           &&visited[dirx][diry]==0
                           &&point[dirx][diry]!='#'){
                            q.push(Point(dirx,diry));
                            visited[dirx][diry]=1;
            }
            }
        }
    if(visited[x2][y2]==1) cout<<"Yes\n";
    else cout<<"No\n";
    }
    return 0;
}