#include <iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;
string s;
vector<string> v;
queue<int> x;
queue<int> y;
int a,b,c;
int vis[100][100]={0};
void BFS(int n)
{
while(vis[1][1]!=1 && x.empty()!=1)
{
if(v[x.front()+1][y.front()]=='1' && vis[x.front()+1][y.front()]==0)
{
vis[x.front()+1][y.front()]=1;
x.push(x.front()+1);
y.push(y.front());
}
else if(v[x.front()][y.front()+1]=='1' && vis[x.front()][y.front()+1]==0)
{
vis[x.front()][y.front()+1]=1;
x.push(x.front());
y.push(y.front()+1);
}
x.pop();
y.pop();
}
}
int main() {
cin>>a>>b;
for(int i=0;i<a;i++)
{
cin>>s;
v.push_back(s);
}
vis[0][0]=1;
x.push(0);
y.push(0);
BFS(0);
}
To embed this project on your website, copy the following code and paste it into your website's HTML: