记录编号 |
48288 |
评测结果 |
AAAAAAAAAA |
题目名称 |
树的最大匹配 |
最终得分 |
100 |
用户昵称 |
Vow Ryan |
是否通过 |
通过 |
代码语言 |
Pascal |
运行时间 |
0.004 s |
提交时间 |
2012-11-05 14:29:50 |
内存使用 |
4.09 MiB |
显示代码纯文本
var
f,g:array[0..1010,0..1]of int64;
a:array[0..1010,0..1010]of longint;
vis:array[0..1010]of boolean;
i,j,k,l,m,n,root,ans:longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
procedure dp(u:longint);
var
i,v:longint;
k:int64;
begin
g[u,1]:=1;
for i:=1 to a[u,0] do
begin
v:=a[u,i];
dp(v);
f[u,1]:=f[u,1]+f[v,0];
g[u,1]:=g[u,1]*g[v,0];
end;
f[u,0]:=f[u,1];
k:=0;
for i:=1 to a[u,0] do
begin
v:=a[u,i];
if f[v,1]+1>f[v,0] then
begin
f[u,0]:=f[u,1]+1;
g[u,0]:=g[u,0]+g[u,1] div g[v,0]*g[v,1];
end;
if (f[u,0]=f[u,1])and(f[v,1]+1=f[v,0]) then k:=k+g[u,1] div g[v,0]*g[v,1];
end;
if f[u,0]=f[u,1] then g[u,0]:=g[u,1]+k;
end;
begin
assign(input,'treeb.in');reset(input);
assign(output,'treeb.out');rewrite(output);
read(n);
for i:=1 to n do
begin
read(k,a[k,0]);
for j:=1 to a[k,0] do read(a[k,j]);
for j:=1 to a[k,0] do vis[a[k,j]]:=true;
end;
for i:=1 to n do
if not vis[i] then root:=i;
dp(root);
writeln(f[root,0],' ',g[root,0]);
close(input);close(output);
end.