Avoid the Lakes
Description
Farmer John's farm was flooded in the most recent storm, a fact-only aggravated by the information so his cows is death Ly afraid of water. His insurance agency would only repay him, however, a amount depending on the size of the largest "lake" on his farm.
The farm is represented as a rectangular grid with N (1≤ n ≤100) rows and m (1≤ m ≤ ) columns. Each cell in the grid is either dry or submerged, and exactly K (1≤ k ≤ N x M) of the Cells are submerged. As one would expect, a lake has a central cell to which and other cells connect by sharing a long edge (not a corner). Any cell this shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected C Ell and is part of the lake.
Input
* Line 1:three space-separated integers: N, M, and K
* Lines 2. K+1:line i+1 describes one submerged location with II space separated integers that is its row and co Lumn: R and C
Output
* Line 1:the number of cells the the largest lake contains.
Sample Input
3 4 53 22 23 12 31 1
Sample Output
4
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 intmap[ the][ the];7 intm,n,cnt;8 intd[4][2]={1,0,0,1,-1,0,0,-1};9 Ten voidDfsintXinty) One { A if(x<=0|| x>m| | y<=0|| y>n| | map[x][y]==0) - return; -map[x][y]=0; thecnt++; - for(intI=0;i<4; i++) - { - intxx=x+d[i][0]; + intyy=y+d[i][1]; - DFS (XX,YY); + } A at } - - intMain () - { - intI,j,x,y,k,ans; - while(SCANF ("%d%d%d", &m,&n,&k)! =EOF) in { -ans=0; tomemset (Map,0,sizeof(map)); + for(i=0; i<k;i++) - { thescanf"%d%d",&x,&y); *map[x][y]=1; $ }Panax Notoginseng for(i=1; i<=m;i++) - for(j=1; j<=n;j++) the { + if(map[i][j]==1) A { theCnt=0; + DFS (I,J); -ans=Max (Cnt,ans); $ } $ } -printf"%d\n", ans); - } the return 0; -}
POJ 3620 Avoid the Lakes