1 #include<iostream>
2 #include<cstdio>
3
4 using namespace std;
5
6 char s[7][7];
7 int n, m,wall,ok;
8 int visit[7][7];
9 int si, sj;
10 int dir[4][2] = {-1,0,0,1,1,0,0,-1};//四个方向,这是做DFS常用的方法,要谨记。
11
12 int dfs(int x,int y,int num)
13 {
14 if(num==n*m-wall-1)
15 return ok = 1;
16 for (int i=0; i<4; i++)
17 {
18 int x1 = x + dir[i][0];
19 int y1 = y + dir[i][1];
20 if (x1>=1&&x1<=n&&y1>=1&&y1<=m&&visit[x1][y1]==0&&s[x1][y1]!='S')
21 {
22 visit[x1][y1] = 1;
23 dfs(x1,y1,num+1);
24 visit[x1][y1] = 0;//回溯饭标记
25 }
26 }
27 }
28
29 int main()
30 {
31 while(cin>>n>>m)
32 {
33 if(n==0 && m==0) break;
34 wall = 0;
35 for(int i=1; i<=n; i++)
36 for(int j=1; j<=m; j++)
37 {
38 cin>>s[i][j];
39 if(s[i][j]=='S')
40 {
41 wall++;
42 }
43 si = 1;
44 sj = 1;
45 visit[i][j] = 0;
46 }
47 ok = 0;
48 visit[si][sj] = 1;
49 dfs(si,sj,0);
50 if (ok == 1)
51 printf("YES\n");
52 else
53 printf("NO\n");
54 }
55 return 0;
56 }