#include
#include
#define maxn 101
int n, m, k, count;
int buf[maxn][maxn];
int vis[maxn][maxn];
int dir[8] = {-1, 0, 1, 0, 0, -1, 0, 1};
void dfs(int x, int y){
int d;
vis[x][y] = 1; ++count;
for(d = 0; d < 8; d+=2){
int nx = x+dir[d], ny = y+dir[d+1];
if(nx>=1 && ny>=1 && nx<=n && ny<=m && !vis[nx][ny] && buf[nx][ny]){
dfs(nx, ny);
}
}
}
int main(){
int max, i, j;
while(scanf("%d%d%d", &n, &m, &k)==3 && n){
max = 0;
memset(buf, 0, sizeof(buf));
memset(vis, 0, sizeof(vis));
while(k--){
scanf("%d%d", &i, &j);
buf[i][j] = 1;
}
for(i = 1; i <= n; ++i)
for(j = 1; j <= m; ++j)
if(!vis[i][j] && buf[i][j]){
count = 0;
dfs(i, j);
if(max < count) max = count;
}
printf("%d\n", max);
}
}
poj 3620 深搜
最新推荐文章于 2014-07-15 18:04:52 发布