记录编号 137499 评测结果 AAAAAAAAAA
题目名称 [USACO Nov07] 最大的湖 最终得分 100
用户昵称 Gravatarhelloworld123 是否通过 通过
代码语言 Pascal 运行时间 0.012 s
提交时间 2014-11-04 20:46:59 内存使用 0.20 MiB
显示代码纯文本
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.