-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
52 lines (50 loc) · 1.18 KB
/
Copy pathmain.cpp
File metadata and controls
52 lines (50 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 98765432
#define MAX_SIZE 501
#define EMPTY 0
#define PAINTED 1
#define VISITED 2
using namespace std;
int N, M, cnt, paints, largest;
int map[MAX_SIZE][MAX_SIZE];
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
void dfs(int r, int c) {
for(int d=0; d<4; d++) {
int nr = r + dr[d];
int nc = c + dc[d];
if(nr < 0 || nr >= N || nc < 0 || nc >= M) continue;
if(map[nr][nc] != PAINTED) continue;
map[nr][nc] = VISITED;
cnt++;
dfs(nr,nc);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M;
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
cin >> map[i][j];
}
}
largest = -1;
for(int i=0; i<N; i++) {
for(int j=0; j<M; j++) {
if(map[i][j] == PAINTED) {
cnt = 1;
paints++;
map[i][j] = VISITED;
dfs(i,j);
if(largest < cnt) largest = cnt;
}
}
}
cout << paints << '\n';
if(largest != -1) cout << largest << '\n';
else cout << "0\n";
return 0;
}