讨论 / 为什么这样直接找它所属的顶点不行?
Fish、のTorres 2011-10-25 05:45:00
点我顶贴 收藏 删除
var a,b,sum,c,d,n,m,q,i:longint;

f,e:array[0..1005]of longint;

x:char;

function s(x:longint):longint;

begin

if f[x]=x then exit(x) else s:=s(f[x]);

end;

begin

readln(n);readln(m);

for i:=1 to n

do f[i]:=i;

for i:=1 to m do begin

readln(x,a,b);

c:=s(a);d:=s(b);

if x='F' then begin

f[d]:=c;

end

else begin

if e[c]<>0 then f[d]:=e[c];

if e[d]<>0 then f[c]:=e[d];

if e[c]=0 then e[c]:=d;

if e[d]=0 then e[d]:=c;

end;

end;

for i:=1 to n do

if f[i]=i then inc(sum);

writeln(sum);

end.

查看更多回复
提交回复