记录编号 |
33247 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Nov10] 拜访奶牛 |
最终得分 |
100 |
用户昵称 |
Des. |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.133 s |
提交时间 |
2011-11-09 20:41:27 |
内存使用 |
1.78 MiB |
显示代码纯文本
program vacation;
uses math;
var f:array[1..50000,0..1]of longint;
a:array[1..50000,1..2]of longint;
q,next:array[0..100000]of longint;
t,k,m,n,i,j,tot:longint;
procedure treedp(i,p:longint);
var t,k,j:longint;
begin
if (a[i,1]=a[i,2])and(q[a[i,1]]=p) then
begin
f[i,0]:=0;
f[i,1]:=1;
exit;
end;
t:=a[i,1];
repeat
if q[t]<>p then
treedp(q[t],i);
t:=next[t];
until t=0;
f[i,1]:=1;
t:=a[i,1];
repeat
if q[t]<>p then
begin
f[i,0]:=f[i,0]+max(f[q[t],1],f[q[t],0]);
f[i,1]:=f[i,1]+f[q[t],0];
end;
t:=next[t];
until t=0;
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);
if a[i,1]=0 then
begin
inc(tot);
a[i,1]:=tot;
a[i,2]:=tot;
q[tot]:=j;
end
else
begin
inc(tot);
next[a[i,2]]:=tot;
a[i,2]:=tot;
q[tot]:=j;
end;
if a[j,1]=0 then
begin
inc(tot);
a[j,1]:=tot;
a[j,2]:=tot;
q[tot]:=i;
end
else
begin
inc(tot);
next[a[j,2]]:=tot;
a[j,2]:=tot;
q[tot]:=i;
end;
end;
treedp(1,0);
writeln(max(f[1,0],f[1,1]));
close(output);
end.