Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_DEPRECATE
- #include <queue>
- #include <cstdio>
- using namespace std;
- typedef pair<int, int> pii;
- int n, m;
- bool used[31][31] = {0};
- int dx[] = {0, 0, 1, -1};
- int dy[] = {-1, 1, 0, 0};
- int bfs(pii from) {
- int res = 1;
- queue <pii> q;
- used[from.first][from.second] = true;
- q.push(from);
- while (!q.empty()) {
- pii cur = q.front();
- q.pop();
- for (int i = 0; i < 4; i++) {
- pii to = cur;
- to.first += dx[i];
- to.second += dy[i];
- if (to.first > n - 1 || to.first < 0) continue;
- if (to.second > m - 1 || to.second < 0) continue;
- if (used[to.first][to.second]) continue;
- q.push(to);
- res++;
- used[to.first][to.second] = true;
- }
- }
- return res;
- }
- int main() {
- freopen("test.in", "r", stdin);
- freopen("test.out", "w", stdout);
- int maxval = 0;
- scanf("%d %d ", &n, &m);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++) {
- char x;
- scanf("%c ", &x);
- if (!(x - '0')) continue;
- used[i][j] = true;
- }
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++) {
- if (used[i][j]) continue;
- int cur = bfs(pii(i, j));
- maxval = cur > maxval ? cur : maxval;
- }
- printf("%d", maxval);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement