var
r,f:array[1..1000]of longint;
ch:char;
i,p,q,n,m,ans:longint;
function find(x:longint):longint;
begin
if f[x]=0 then exit(x);
find:=find(f[x]);
f[x]:=find;
end;
procedure union(x,y:longint);
var
a,b:longint;
begin
if x=y then exit;
a:=find(x);b:=find(y);
if a<>b then f[b]:=a;
end;
begin
fillchar(f,sizeof(f),0);fillchar(r,sizeof(r),0);ans:=0;
readln(n);
readln(m);
for i:=1 to m do begin
readln(ch,p,q);
if ch='F' then union(p,q)
//本来我在这里加了
if r[p]=0 then r[p]:=r[q];
if r[q]=0 then r[q]:=r[p];
这两句是为了防止p,q中的某一个是第一次出现而没有记录其敌人集合
可是只过了4个点,可是删掉这两句就AC了!很显然测试数据有错.
//
else
begin
if r[p]=0 then r[p]:=q;
if r[q]=0 then r[q]:=p;
union(p,r[q]);
union(q,r[p]);
end;
end;
for i:=1 to n do
if f[i]=0 then inc(ans);
writeln(ans);
readln;
end.
求神牛解释
Maybe~下面是我的个人理解~不代表rqnoj网站的观点~
[color=red]三国鼎立[/color],三国[color=green]互为敌人[/color],[color=blue]敌人的敌人[/color]明明是[color=pink]敌人[/color]啊~
按照题目来说~[color=red]敌人的敌人[/color]~变成[color=green]朋友[/color]了~[color=pink]汗[/color]~