You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
912 B
39 lines
912 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 110;
|
|
char a[N][N];
|
|
#define x first
|
|
#define y second
|
|
typedef pair<int, int> PII;
|
|
int dx[] = {-1, 0, 1, 0}; //上右下左
|
|
int dy[] = {0, 1, 0, -1}; //上右下左
|
|
int main() {
|
|
int n, m;
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= m; j++)
|
|
cin >> a[i][j];
|
|
|
|
queue<PII> q;
|
|
q.push({1, 1});
|
|
while (q.size()) {
|
|
auto t = q.front();
|
|
q.pop();
|
|
for (int i = 0; i < 4; i++) {
|
|
int tx = t.x + dx[i], ty = t.y + dy[i];
|
|
if (tx == 0 || tx > n || ty == 0 || ty > m) continue;
|
|
if (a[tx][ty] == '0') {
|
|
a[tx][ty] = 'x';
|
|
q.push({tx, ty});
|
|
}
|
|
}
|
|
}
|
|
|
|
if (a[n][m] == 'x')
|
|
cout << "yes" << endl;
|
|
else
|
|
cout << "no" << endl;
|
|
return 0;
|
|
}
|