Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

ft...我也陷入了wa和re中.....st大大帮我看看‘D’的那段吧...~

Posted by palmtenor at 2005-06-07 15:31:12 on Problem 1703
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator