题面:

 

思路:

 

 

代码:

var map:array[0..201,0..201] of boolean;
 father:array[0..201] of longint;
  i,j,k,n,t:longint;

begin

 assign(input,'cdrom.in');
 reset(input);
 assign(output,'cdrom.out');
 rewrite(output);

 fillchar(map,sizeof(map),false);
 read(n);
 for i:=1 to n do
  begin
   read(t);
   while t<>0 do
    begin
     map[i,t]:=true;
     read(t);
    end;
  end;

 for k:=1 to n do
  for i:=1 to n do
   for j:=1 to n do
    if map[i,k] and map[k,j] then map[i,j]:=true;
 for i:=1 to n do father[i]:=i;
  for i:=1 to n do
   for j:=1 to n do
    if map[i,j] then father[j]:=father[i];
 t:=0;
 for i:=1 to n do
  if father[i]=i then inc(t);
 write(t);

 close(input);close(output);

end.

 

posted on 2018-10-04 14:07  Tolye  阅读(96)  评论(0编辑  收藏  举报