| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
pascal 题解program POJ1703;
const
maxn=100010;
Var
f:array[0..maxn]of longint;
v:array[0..maxn]of integer;
t,i:longint;
s:char;
function find(x:longint):longint;
var
k:longint;
begin
if(f[x]=x)then exit(x);
k:=f[x];
f[x]:=find(f[x]);
v[x]:=(v[x]+v[k])and 1;
exit(f[x]);
end;
procedure work;
var
n,m,i,x,y:longint;
begin
fillchar(f,sizeof(f),0);
fillchar(v,sizeof(v),0);
readln(n,m);
for i:=1 to n do f[i]:=i;
for i:=1 to m do
begin
readln(s,x,y);
if(s='A')then
begin
if(find(x)=find(y))then
if(v[x]=v[y])then writeln('In the same gang.')
else writeln('In different gangs.')
else writeln('Not sure yet.');
end
else
if(find(x)<>find(y))then
begin
v[f[x]]:=((v[x]+v[y])+1)and 1;
f[f[x]]:=f[y];
end;
end;
end;
Begin
readln(t);
for i:=1 to t do work;
End.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator