ac

逸尘  •  1年前


include <bits/stdc++.h>

using namespace std; int n, m, ans, maxa; int a[105][105];

int dfs(int x, int y) {

ans++;
a[x][y] = 0;

if (a[x - 1][y] == 1) {
	dfs(x - 1, y);
}

if (a[x + 1][y] == 1) {
	dfs(x + 1, y);
}

if (a[x][y - 1] == 1) {
	dfs(x, y - 1);
}

if (a[x][y + 1] == 1) {
	dfs(x, y + 1);
}

return ans;

}

int main() {

cin >> n >> m;

for (int i = 1; i <= n; i++) {

	for (int j = 1; j <= m; j++) {

		cin >> a[i][j];
	}
}

for (int i = 1; i <= n; i++) {

	for (int j = 1; j <= m; j++) {

		if (a[i][j] == 1) {
			ans = 0;
			maxa = max(maxa, dfs(i, i));
		}
	}
}

cout << maxa;
return 0;

}


评论:

请先登录,才能进行评论