-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2468.cpp
69 lines (62 loc) · 1.34 KB
/
2468.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <queue>
#define PAIR pair<int,int>
using namespace std;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int graph[100][100];
int visited[100][100];
queue<PAIR> q;
int N;
void INIT(){
for(int i=0; i<N;i++){
for(int j=0;j<N;j++){
visited[i][j]=0;
}
}
}
void BFS(int sx,int sy,int maxx){
q.push(PAIR(sx,sy));
visited[sy][sx]=1;
while(!q.empty()){
int vx = q.front().first;
int vy = q.front().second;
q.pop();
for(int i=0; i<4; i++){
int xx = vx+dx[i];
int yy = vy+dy[i];
if(xx>=0&&xx<N&&yy>=0&&yy<N&&graph[yy][xx]>maxx&&visited[yy][xx]==0){
q.push(PAIR(xx,yy));
visited[yy][xx]=1;
}
}
}
}
int main(){
cin >> N;
int maxx=-1;
int re=0;
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
int a; cin >> a;
if(maxx<a)
maxx=a;
graph[i][j]=a;
}
}
for(int k=0; k<=maxx; k++){
int cnt=0;
INIT();
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
if(graph[i][j]>k&&visited[i][j]==0){
cnt++;
BFS(j,i,k);
}
}
}
if(re<cnt)
re=cnt;
}
cout << re;
}