记录编号 49159 评测结果 AAAAAAAAAA
题目名称 树的最大匹配 最终得分 100
用户昵称 Gravatar天下第一的吃货殿下 是否通过 通过
代码语言 Pascal 运行时间 0.003 s
提交时间 2012-11-07 13:42:10 内存使用 2.10 MiB
显示代码纯文本
var
 a,b,d,e,n,c:longint;
 gs:array[0..1001] of integer;
 qq:array[0..1001,0..1001] of integer;
 pd:array[0..1001] of boolean;
 jl:array[0..1001,0..1] of int64;
 bs:array[0..1001,0..1] of integer;
 zg:int64;
  function max(xx,yy:int64):int64;
      begin
         if xx>yy then exit(xx)
          else exit(yy);
  end;
    function ss(lt,nn:integer):integer;
       var
         i,j,k:longint;
         gss,mb:int64;
          begin
           if bs[nn,lt]<>0 then exit(bs[nn,lt]);
          k:=0;
          j:=0;
          gss:=1;
            if lt=1 then
               for i:=1 to gs[nn] do
                  begin
                k:=k+ss(0,qq[nn,i]);
                gss:=gss*jl[qq[nn,i],0];
               end
                   else   begin
                     for i:=1 to gs[nn] do
                        begin
                       k:=k+ss(0,qq[nn,i]);
                       gss:=gss*jl[qq[nn,i],0];
                     end;
                       j:=k;
                       mb:=gss;
                       for i:=1 to gs[nn] do
                          if j<k-ss(0,qq[nn,i])+1+ss(1,qq[nn,i])
                              then begin
                                j:=k-ss(0,qq[nn,i])+1+ss(1,qq[nn,i]);
                                gss:=(mb div jl[qq[nn,i],0])*jl[qq[nn,i],1];
                            end  else
                          if j=k-ss(0,qq[nn,i])+1+ss(1,qq[nn,i])
                              then begin
                                 gss:=gss+(mb div jl[qq[nn,i],0])*jl[qq[nn,i],1];
                               end;
                         k:=j;
                     end;
                bs[nn,lt]:=k;
                jl[nn,lt]:=gss;
               exit(k);
  end;
  begin
   assign(input,'treeb.in');
     reset(input);
      assign(output,'treeb.out');
       rewrite(output);
   readln(n);
    for a:=1 to n do
        begin
            read(b);
            read(gs[b]);
            for c:=1 to gs[b] do
               begin
               read(qq[b,c]);
               pd[qq[b,c]]:=true;
            end;
          readln;
    end;
  for a:=1 to n do
         if pd[a]=false then begin
            b:=ss(0,a);
             c:=a;
            end;
         writeln(b);
         writeln(jl[1,0]);
  close(input);
   close(output);
end.