显示代码纯文本
#include<iostream>
#include<cstdio>
using namespace std;
int map[101][101];
bool sd[101][101];
int s1[4]={-1,1,0,0};
int s2[4]={0,0,-1,1};
int m,n,ans=0,k,r,c,manx=0,ss=0;
void dfs(int he,int sh)
{
ss++;
map[he][sh]=ans;
for(int i=0;i<=3;i++)
{
if(map[he-s1[i]][sh-s2[i]]==0&&sd[he-s1[i]][sh-s2[i]]==1&&1<=he-s1[i]<=n&&1<=sh-s2[i]<=m)
{
dfs(he-s1[i],sh-s2[i]);
}
}
}
int main()
{
freopen("lake.in","r",stdin);
freopen("lake.out","w",stdout);
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=k;i++)
{
scanf("%d%d",&r,&c);
sd[r][c]=1;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(sd[i][j]==1&&map[i][j]==0)
{
ans++;
ss=0;
dfs(i,j);
manx=max(manx,ss);
}
}
}
cout<<manx<<endl;
return 0;
}