#include<iostream> #include<queue> #include<algorithm> #include<unordered_map> #define x first #define y second #define mk make_pair #define umap unordered_map #define endl '\n' #define ___G std::ios::sync_with_stdio(false),cin.tie(0), cout.tie(0) usingnamespace std;
int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1};
constint N = 1e4 + 10;
int n, m; // 湖泊图大小
umap<int, int>g[N]; // 湖泊图数值 int step; inlinevoidDFS(int x, int y) { if (!g[x][y]) return ; step += g[x][y]; g[x][y] = 0; for (int i = 0; i < 4; ++i) { int bx = x + dx[i]; int by = y + dy[i]; DFS(bx, by); } return ; }
inlinevoidsolve() { int ans = 0; cin >> n >> m; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { cin >> g[i][j]; } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (g[i][j]) { step = 0; DFS(i, j); ans = max(ans, step ); } } } cout << ans << endl; }