比赛 20110923 评测结果 AAAWTTTEEE
题目名称 拜访奶牛 最终得分 30
用户昵称 Des. 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-09-23 21:36:58
显示代码纯文本
program vacation;
var a:array[1..1000,0..1000]of longint;
    l:array[0..1001,1..2]of longint;
    t,k,m,n,i,j,max,z:longint;
procedure sou(i:longint);
var t,k,j:longint;
    p:array[0..100]of longint;
begin
if l[0,2]=n+1 then
  begin
    if i>max then
      max:=i;
    exit;
  end;
if (n-z)+i<=max then exit;
t:=0;
fillchar(p,sizeof(p),0);
repeat
  t:=l[t,2];
  l[l[t,2],1]:=l[t,1];
  l[l[t,1],2]:=l[t,2];
  for k:=1 to a[t,0] do
    begin
      j:=a[t,k];
      if l[l[j,1],2]=j then
        begin
          l[l[j,2],1]:=l[j,1];
          l[l[j,1],2]:=l[j,2];
          inc(p[0]);
          p[p[0]]:=j;
        end;
    end;
  z:=z+a[t,0]+1;
  sou(i+1);
  z:=z-a[t,0]-1;
  for k:=1 to p[0] do
    begin
      j:=p[k];
      l[l[j,2],1]:=j;
      l[l[j,1],2]:=j;
    end;
  p[0]:=0;
  l[l[t,2],1]:=t;
  l[l[t,1],2]:=t;
until l[t,2]=n+1;
end;
begin
assign(input,'vacation.in');
reset(input);
assign(output,'vacation.out');
rewrite(output);
readln(n);
for t:=1 to n-1 do
  begin
    readln(i,j);
    inc(a[i,0]);
    a[i,a[i,0]]:=j;
    inc(a[j,0]);
    a[j,a[j,0]]:=i;
  end;
l[0,2]:=1;
l[n+1,1]:=n;
for t:=1 to n do
  begin
    l[t,1]:=t-1;
    l[t,2]:=t+1;
  end;
z:=0;
for t:=n downto 1 do
  begin
    l[l[t,2],1]:=l[t,1];
    l[l[t,1],2]:=l[t,2];
    for k:=1 to a[t,0] do
      begin
        j:=a[t,k];
        l[l[j,2],1]:=l[j,1];
        l[l[j,1],2]:=l[j,2];
      end;
    z:=z+a[t,0]+1;
    sou(1);
    z:=z-a[t,0]-1;
    for k:=1 to a[t,0] do
      begin
        j:=a[t,k];
        l[l[j,2],1]:=j;
        l[l[j,1],2]:=j;
      end;
    l[l[t,2],1]:=t;
    l[l[t,1],2]:=t;
  end;
writeln(max);
close(output);
end.