#include<bits/stdc++.h>
using namespace std;
int h,w;
int dx[4]={-1,0,0,1};
int dy[4]={0,-1,1,0};
struct xy{
int x,y;
};
char dt[510][510];
char ddd(char a){
switch(a){
case 's':{
return 'n';
}
case 'n':{
return 'u';
}
case 'u':{
return 'k';
}
case 'k':{
return 'e';
}
case 'e':{
return 's';
}
}
}
bool f[510][510];
bool BFS(){
xy fxy;
fxy.x=1;
fxy.y=1;
queue<xy> q;
q.push(fxy);
while(!q.empty()){
xy t=q.front();
q.pop();
if(t.x==h&&t.y==w){
return 1;
}
for(int i=1;i<=4;i++){
xy nt;
nt.x=t.x+dx[i];
nt.y=t.y+dy[i];
if(f[nt.x][nt.y]!=1&&dt[nt.x][nt.y]==ddd(dt[t.x][t.y])){
q.push(nt);
f[nt.x][nt.y]=1;
}
}
}
return 0;
}
int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
cin>>h>>w;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
cin>>dt[i][j];
}
}
if(BFS()==1)
cout<<"Yes\n";
else
cout<<"No\n";
return 0;
}
本地无法输出结果