其余全WA
#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y,s;
};
int r,c;
bool flag[120][80],vis[100005];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
bool check(int x,int y)
{
if(x<1||x>r||y<1||y>c)
return false;
return true;
}
void bfs()
{
cout<<1<<' '<<1<<endl;
queue<node>que;
que.push({1,1,0});
flag[1][1]=1;
while(!que.empty())
{
for(int i=0;i<4;i++)
{
int nx=dx[i]+que.front().x;
int ny=dy[i]+que.front().y;
if(check(nx,ny)&&flag[nx][ny]==0)
{
if(vis[que.front().s+1]==0)
cout<<nx<<' '<<ny<<endl,vis[que.front().s+1]=1;
flag[nx][ny]=1;
que.push({nx,ny,que.front().s+1});
if(nx==r&&ny==c)
return;
}
}
que.pop();
}
}
int main()
{
cin>>r>>c;
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
{
char ch;
cin>>ch;
if(ch=='.')
flag[i][j]=0;
else
flag[i][j]=1;
}
bfs();
return 0;
}