显示代码纯文本
program cogs155;
const
maxn=100;
dx:array[1..4] of longint=(-1,0,1,0);
dy:array[1..4]of longint=(0,-1,0,1);
var
x,y,i,j,n,m,k,ans:longint;
a:array[1..maxn,1..maxn] of longint;
function heshi(x,y:longint):boolean;
begin
if (x<=n)and(x>0)and(y<=m)and(y>0)and(a[x,y]=1)
then exit(true);
exit(false);
end;
procedure bfs(l,r:longint);
var
i,j,front,tail,x,y:longint;
q:array[1..maxn*maxn,1..2] of longint;
begin
front:=0; tail:=1;
q[1,1]:=l; q[1,2]:=r;
a[l,r]:=0;
while front<>tail do
begin
inc(front);
for i:=1 to 4 do
begin
x:=q[front,1]+dx[i];
y:=q[front,2]+dy[i];
if heshi(x,y) then
begin
inc(tail);
a[x,y]:=0;
q[tail,1]:=x; q[tail,2]:=y;
end;
end;
end;
if tail>ans then ans:=tail;
end;
begin
assign(input,'lake.in'); reset(input);
assign(output,'lake.out'); rewrite(output);
readln(n,m,k);
fillchar(a,sizeof(a),0);
for i:=1 to k do
begin
readln(x,y);
a[x,y]:=1;
end;
ans:=-maxlongint;
for i:=1 to n do
for j:=1 to m do
begin
if a[i,j]=1 then
begin
a[i,j]:=0;
bfs(i,j);
end;
end;
writeln(ans);
close(input); close(output);
end.