标签:style blog io ar color sp for on div
一道裸的并查集,练练手不错。
program CODEVS1073; var i,j,m,n,q,x,y,k1,k2,z:longint; f:array[0..10000] of longint; function find(x:longint):longint; var fa:longint; begin while f[x]=x do exit(x); fa:=find(f[x]); f[x]:=fa; exit(fa); end; begin readln(n,m,q); for i:=1 to n do f[i]:=i; for i:=1 to m do begin readln(k1,k2); x:=find(k1); y:=find(k2); f[y]:=x; end; for i:=1 to q do begin readln(k1,k2); x:=find(k1); y:=find(k2); if f[x]=f[y] then writeln(‘Yes‘) else writeln(‘No‘); end; end.
标签:style blog io ar color sp for on div
原文地址:http://www.cnblogs.com/rpSebastian/p/4151906.html