记录编号 81101 评测结果 AAAAAAAAAA
题目名称 [USACO Nov10] 拜访奶牛 最终得分 100
用户昵称 GravatarC语言入门 是否通过 通过
代码语言 Pascal 运行时间 0.057 s
提交时间 2013-11-08 16:52:02 内存使用 1.50 MiB
显示代码纯文本
program o;
var
n,i,x,y,k:longint;
a:array [0..50000] of longint;
b:array [0..100000,1..2] of longint;
f:array [0..50000,0..1] of longint;
function max(a,b:longint):longint;
begin
 if a>b then max:=a
        else max:=b;
end;
function try(fa,k1,q:longint):longint;
var
t,zs:longint;
begin
 if f[k1,q]>=0 then exit(f[k1,q]);
 zs:=0;
 t:=a[k1];
 while t<>0 do
  begin
   if fa<>b[t,1] then
    begin
     if q=0 then inc(zs,max(try(k1,b[t,1],0),try(k1,b[t,1],1)))
            else inc(zs,try(k1,b[t,1],0));
    end;
   t:=b[t,2];
  end;
 if q=1 then inc(zs);
 f[k1,q]:=zs;
 exit(zs);
end;
begin
assign (input,'vacation.in');
assign (output,'vacation.out');
reset (input);
rewrite (output);
fillchar (f,sizeof(f),128);
 read (n);
 for i:=1 to n-1 do
  begin
   read (x,y);
   inc(k);
   b[k,1]:=x;
   b[k,2]:=a[y];
   a[y]:=k;
   inc(k);
   b[k,1]:=y;
   b[k,2]:=a[x];
   a[x]:=k;
  end;
 write (max(try(0,1,0),try(0,1,1)));
close (input);
close (output);
end.