12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #include <bits/stdc++.h>
- using namespace std;
-
- const int MXAN = 200 + 10;
- int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
- int a[MXAN][MXAN];
- int sum[MXAN][MXAN];
- int n, m;
-
- int Bfs(int x, int y)
- {
- int res = 0;
- queue<pair<int, int> > que;
- que.push(make_pair(x, y));
- a[x][y] = 0;
- while (!que.empty())
- {
- res++;
- int x = que.front().first;
- int y = que.front().second;
- que.pop();
- for (int i = 0;i < 4;i++)
- {
- int tx = x + Next[i][0];
- int ty = y + Next[i][1];
- if (a[tx][ty] == 1)
- {
- a[tx][ty] = 0;
- que.push(make_pair(tx, ty));
- }
- }
- }
- return res;
- }
-
- int main()
- {
- int t;
- cin >> t;
- while (t--)
- {
-
- cin >> n >> m;
- for (int i = 1;i <= n;i++)
- for (int j = 1;j <= m;j++)
- cin >> a[i][j];
- int res = 0;
- for (int i = 1;i <= n;i++)
- for (int j = 1;j <= m;j++)
- {
- if (a[i][j] == 1)
- {
- res = max(res, Bfs(i, j));
-
- }
- }
- cout << res << endl;
- }
-
- return 0;
- }
|