Language: C++

#include<bits/stdc++.h>
using namespace std;
int INF = 1e8;
struct edge{ int to,cap,rev; };
vector<edge> G[5000];
bool used[5000];

void init_edge(){
  for(int i=0;i<5000;i++){
    G[i].clear();
  }
}

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  if(s==t)return INF;
  
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)break;
    flow+=f;
  }

  return flow;
}


int N,M;
char c[100][100];
int di[]={-1,0,1,0};
int dj[]={0,1,0,-1};

int calc(int y,int x){
  return y*M+x;
}

void make_graph(){
  init_edge();  
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      int flg=1;
      if( i==0 && j== 0)flg=2;
      if( i==0 && j==M-1)flg=2;
      if( i==N-1 && j==0)flg=2;
      if( i==N-1 && j==M-1)flg=2;
      add_edge( calc(i,j) , calc(i,j) + N*M , flg);
      
      for(int dir=0;dir<4;dir++){
        int ni=i+di[dir];
        int nj=j+dj[dir];
        if(ni<0 || nj<0 || ni>=N || nj>=M)continue;
        if(c[ni][nj]=='#')continue;
        if(c[i][j]=='#')continue;
        
        add_edge( calc(i,j)+N*M , calc(ni,nj) , 1);
      }
    }
  }
}

int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        cin>>c[i][j];
      }
    }

    make_graph();
    if( max_flow( calc(0,0) , calc(N-1,M-1)+N*M ) < 2){
      cout<<"NO"<<endl;
      continue;
    }


    
    make_graph();
    if( max_flow( calc(0,M-1) , calc(N-1,0)+N*M ) < 2){
      cout<<"NO"<<endl;
      continue;
    }

    cout<<"YES"<<endl;
  }

  return 0;
}
#include<bits/stdc++.h>
using namespace std;
int INF = 1e8;
struct edge{ int to,cap,rev; };
vector<edge> G[5000];
bool used[5000];

void init_edge(){
  for(int i=0;i<5000;i++){
    G[i].clear();
  }
}

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  if(s==t)return INF;
  
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)break;
    flow+=f;
  }

  return flow;
}


int N,M;
char c[100][100];
int di[]={-1,0,1,0};
int dj[]={0,1,0,-1};

int calc(int y,int x){
  return y*M+x;
}

void make_graph(){
  init_edge();  
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      int flg=1;
      if( i==0 && j== 0)flg=2;
      if( i==0 && j==M-1)flg=2;
      if( i==N-1 && j==0)flg=2;
      if( i==N-1 && j==M-1)flg=2;
      add_edge( calc(i,j) , calc(i,j) + N*M , flg);
      
      for(int dir=0;dir<4;dir++){
        int ni=i+di[dir];
        int nj=j+dj[dir];
        if(ni<0 || nj<0 || ni>=N || nj>=M)continue;
        if(c[ni][nj]=='#')continue;
        if(c[i][j]=='#')continue;
        
        add_edge( calc(i,j)+N*M , calc(ni,nj) , 1);
      }
    }
  }
}

int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    
    for(int i=0;i<N;i++){
      for(int j=0;j<M;j++){
        cin>>c[i][j];
      }
    }

    make_graph();
    if( max_flow( calc(0,0) , calc(N-1,M-1)+N*M ) < 2){
      cout<<"NO"<<endl;
      continue;
    }


    
    make_graph();
    if( max_flow( calc(0,M-1) , calc(N-1,0)+N*M ) < 2){
      cout<<"NO"<<endl;
      continue;
    }

    cout<<"YES"<<endl;
  }

  return 0;
}

Compiler output:
a.cc:115:5: error: redefinition of 'int INF'
  115 | int INF = 1e8;
      |     ^~~
a.cc:3:5: note: 'int INF' previously defined here
    3 | int INF = 1e8;
      |     ^~~
a.cc:116:8: error: redefinition of 'struct edge'
  116 | struct edge{ int to,cap,rev; };
      |        ^~~~
a.cc:4:8: note: previous definition of 'struct edge'
    4 | struct edge{ int to,cap,rev; };
      |        ^~~~
a.cc:117:14: error: redefinition of 'std::vector<edge> G [5000]'
  117 | vector<edge> G[5000];
      |              ^
a.cc:5:14: note: 'std::vector<edge> G [5000]' previously declared here
    5 | vector<edge> G[5000];
      |              ^
a.cc:118:6: error: redefinition of 'bool used [5000]'
  118 | bool used[5000];
      |      ^~~~
a.cc:6:6: note: 'bool used [5000]' previously declared here
    6 | bool used[5000];
      |      ^~~~
a.cc:120:6: error: redefinition of 'void init_edge()'
  120 | void init_edge(){
      |      ^~~~~~~~~
a.cc:8:6: note: 'void init_edge()' previously defined here
    8 | void init_edge(){
      |      ^~~~~~~~~
a.cc:126:6: error: redefinition of 'void add_edge(int, int, int)'
  126 | void add_edge(int from,int to,int cap){
      |      ^~~~~~~~
a.cc:14:6: note: 'void add_edge(int, int, int)' previously defined here
   14 | void add_edge(int from,int to,int cap){
      |      ^~~~~~~~
a.cc:131:5: error: redefinition of 'int dfs(int, int, int)'
  131 | int dfs(int v,int t,int f){
      |     ^~~
a.cc:19:5: note: 'int dfs(int, int, int)' previously defined here
   19 | int dfs(int v,int t,int f){
      |     ^~~
a.cc:147:5: error: redefinition of 'int max_flow(int, int)'
  147 | int max_flow(int s,int t){
      |     ^~~~~~~~
a.cc:35:5: note: 'int max_flow(int, int)' previously defined here
   35 | int max_flow(int s,int t){
      |     ^~~~~~~~
a.cc:162:5: error: redefinition of 'int N'
  162 | int N,M;
      |     ^
a.cc:50:5: note: 'int N' previously declared here
   50 | int N,M;
      |     ^
a.cc:162:7: error: redefinition of 'int M'
  162 | int N,M;
      |       ^
a.cc:50:7: note: 'int M' previously declared here
   50 | int N,M;
      |       ^
a.cc:163:6: error: redefinition of 'char c [100][100]'
  163 | char c[100][100];
      |      ^
a.cc:51:6: note: 'char c [100][100]' previously declared here
   51 | char c[100][100];
      |      ^
a.cc:164:5: error: redefinition of 'int di []'
  164 | int di[]={-1,0,1,0};
      |     ^~
a.cc:52:5: note: 'int di [4]' previously defined here
   52 | int di[]={-1,0,1,0};
      |     ^~
a.cc:165:5: error: redefinition of 'int dj []'
  165 | int dj[]={0,1,0,-1};
      |     ^~
a.cc:53:5: note: 'int dj [4]' previously defined here
   53 | int dj[]={0,1,0,-1};
      |     ^~
a.cc:167:5: error: redefinition of 'int calc(int, int)'
  167 | int calc(int y,int x){
      |     ^~~~
a.cc:55:5: note: 'int calc(int, int)' previously defined here
   55 | int calc(int y,int x){
      |     ^~~~
a.cc:171:6: error: redefinition of 'void make_graph()'
  171 | void make_graph(){
      |      ^~~~~~~~~~
a.cc:59:6: note: 'void make_graph()' previously defined here
   59 | void make_graph(){
      |      ^~~~~~~~~~
a.cc:195:5: error: redefinition of 'int main()'
  195 | int main(){
      |     ^~~~
a.cc:83:5: note: 'int main()' previously defined here
   83 | int main(){
      |     ^~~~