#include<string.h>
#include <stdio.h>
![](/Images/OutliningIndicators/None.gif)
int m, n;
bool link[22][22];
bool v[22][22];
![](/Images/OutliningIndicators/None.gif)
bool ll;
bool lll;
int bi,bj,ei,ej;
int c1;
void dfs(int i,int j)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
v[i][j]=1;
if(i-1>=0 && v[i-1][j]==0 && link[i-1][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dfs(i-1,j);
}
if(j-1>=0 && v[i][j-1]==0 && link[i][j-1]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dfs(i,j-1);
}
if(i+1<n && v[i+1][j]==0 && link[i+1][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dfs(i+1,j);
}
if(j+1<m && v[i][j+1]==0 && link[i][j+1]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
dfs(i,j+1);
}
}
![](/Images/OutliningIndicators/None.gif)
void DFS(int i,int j)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
![](/Images/OutliningIndicators/InBlock.gif)
bool ss=0;
v[i][j]=1;
bool vv[21][21];
int i1,j1;
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
vv[i1][j1]=v[i1][j1];
![](/Images/OutliningIndicators/InBlock.gif)
v[i][j]=0;
int ccc=0;
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(v[i1][j1]==0 && link[i1][j1]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int cc=0;
if(i1-1>=0 && v[i1-1][j1]==0&& link[i1-1][j1]==0)
cc++;
if(j1-1>=0 && v[i1][j1-1]==0&& link[i1][j1-1]==0)
cc++;
if(i1+1<n && v[i1+1][j1]==0&& link[i1+1][j1]==0)
cc++;
if(j1+1<m && v[i1][j1+1]==0&& link[i1][j1+1]==0)
cc++;
if(cc==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
ccc++;
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
bool con=1;
![](/Images/OutliningIndicators/InBlock.gif)
if(ccc>2) con=0;
![](/Images/OutliningIndicators/InBlock.gif)
v[i][j]=1;
![](/Images/OutliningIndicators/InBlock.gif)
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
if(link[i1][j1]==0 && v[i1][j1]==0)
dfs(i1,j1);
![](/Images/OutliningIndicators/InBlock.gif)
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
if(v[i1][j1]==0 && link[i1][j1]==0)
con=0;
![](/Images/OutliningIndicators/InBlock.gif)
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
v[i1][j1]=vv[i1][j1];
![](/Images/OutliningIndicators/InBlock.gif)
if(con)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
![](/Images/OutliningIndicators/InBlock.gif)
if(i-1>=0 && v[i-1][j]==0 && link[i-1][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
v[i1][j1]=vv[i1][j1];
![](/Images/OutliningIndicators/InBlock.gif)
DFS(i-1,j);
ss=1;
}
if(j-1>=0 && v[i][j-1]==0 && link[i][j-1]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
v[i1][j1]=vv[i1][j1];
![](/Images/OutliningIndicators/InBlock.gif)
DFS(i,j-1);
ss=1;
}
if(i+1<n && v[i+1][j]==0 && link[i+1][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
v[i1][j1]=vv[i1][j1];
![](/Images/OutliningIndicators/InBlock.gif)
DFS(i+1,j);
ss=1;
}
if(j+1<m && v[i][j+1]==0 && link[i][j+1]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
v[i1][j1]=vv[i1][j1];
![](/Images/OutliningIndicators/InBlock.gif)
DFS(i,j+1);
ss=1;
}
![](/Images/OutliningIndicators/InBlock.gif)
if(ss==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
ll=1;
for(i1=0;i1<n;i1++)
for(j1=0;j1<m;j1++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(v[i1][j1]==0 && link[i1][j1]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
ll=0;
i1=n,j1=m;
break;
}
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) if(ll) {
lll=1;
return;}
}
}
}
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
int main()
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](/Images/OutliningIndicators/ContractedBlock.gif) {
![](/Images/OutliningIndicators/InBlock.gif)
while(scanf("%d%d",&n,&m)==2)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
lll=0;
ll=1;
memset(v,0,sizeof(v));
if(m==0 && n==0)break;
int i, j;
for(i=0;i<n;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(j=0;j<m;j++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
scanf("%d",&link[i][j]);
}
}
ei=21,ej=21;
c1=0;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(v[i][j]==0 && link[i][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int cc=0;
if(i-1>=0 && v[i-1][j]==0&& link[i-1][j]==0)
cc++;
if(j-1>=0 && v[i][j-1]==0&& link[i][j-1]==0)
cc++;
if(i+1<n && v[i+1][j]==0&& link[i+1][j]==0)
cc++;
if(j+1<m && v[i][j+1]==0 && link[i][j+1]==0)
cc++;
if(cc==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
bi=i,bj=j;
c1++;
i=n,j=m;
v[bi][bj]=1;
break;
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
for(i=0;i<n;i++)
for(j=0;j<m;j++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(v[i][j]==0 && link[i][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
int cc=0;
if(i-1>=0 && v[i-1][j]==0&& link[i-1][j]==0)
cc++;
if(j-1>=0 && v[i][j-1]==0&& link[i][j-1]==0)
cc++;
if(i+1<n && v[i+1][j]==0&& link[i+1][j]==0)
cc++;
if(j+1<m && v[i][j+1]==0&& link[i][j+1]==0)
cc++;
if(cc==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
c1++;
ei=i,ej=j;
i=n,j=m;
break;
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
if(c1==1 || c1==2)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
memset(v,0,sizeof(v));
DFS(bi,bj);
}
if(c1==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i=0;i<n;i++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(j=0;j<m;j++)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
if(link[i][j]==0)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
memset(v,0,sizeof(v));
DFS(i,j);
}
![](/Images/OutliningIndicators/InBlock.gif)
if(lll==1)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
i=n,j=m;
break;
}
}
}
}
![](/Images/OutliningIndicators/InBlock.gif)
if(lll)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
|
|