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 |
ft...我也陷入了wa和re中.....st大大帮我看看‘D’的那段吧...~In Reply To:郁闷了好久怎么处理中间节点之间的互斥关系,忽然才想到调整根就可以了 Posted by:frkstyc at 2005-05-16 19:38:19 const maxn=100000; var f,d:array[1..maxn] of longint; ta,tb,i,j,k,l,m,n,t,s,cs:longint; cc:char; procedure init(nn:longint); var i:longint; begin for i:=1 to nn do begin f[i]:=i; d[i]:=0; end; end; function ff(k:longint):longint; var t:longint; begin if f[k]=k then exit(k); t:=ff(f[k]); inc(d[k],d[f[k]]); f[k]:=t; exit(t); end; begin readln(cs); for cs:=cs downto 1 do begin readln(n,m); init(n); for i:=1 to m do begin read(cc); readln(ta,tb); if cc='A' then begin if ff(ta)<>ff(tb) then writeln('Not sure yet.') else begin if (d[ta] mod 2)=(d[tb] mod 2) then writeln('In the same gang.') else writeln('In different gangs.'); end; end; if cc='D' then begin if ff(ta)=ff(tb) then continue; if (d[ta] mod 2)=0 then begin inc(d[ff(ta)]); f[ff(ta)]:=tb; continue; end; if (d[tb] mod 2)=0 then begin inc(d[ff(tb)]); f[ff(tb)]:=ta; continue; end; inc(d[ff(tb)]); f[ff(tb)]:=ff(ta); end; end; end; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator