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

样例能过,但是提示答案错误,求改正。

Posted by sdyyyztlh at 2014-01-13 14:41:19 on Problem 1703
program poj1703;
type
  node=record
    diff:longint;
    father:longint;
    shunxu:longint;
end;
var
   a:array[1..100005] of node;
   x,y,j1,i,j,k,l,m,n:longint;
   c1,c:char;
function find(jj:longint):longint;
  begin
    if (a[jj].father<>jj) then
      a[jj].father:=find(a[jj].father);
    exit(a[jj].father);
  end;
procedure hebing(xx,yy:longint);
 begin
  if (a[xx].shunxu>a[yy].shunxu) then
      a[yy].father:=xx
  else
     begin
      a[xx].father:=yy;
      if (a[xx].shunxu=a[yy].shunxu) then
         a[yy].shunxu:=a[yy].shunxu+1;
     end;
 end;


begin
  readln(l);
  readln(n,m);
for j1:=1 to l do
 begin
  for i:=1 to n do
    begin
      a[i].diff:=0;
      a[i].shunxu:=0;
      a[i].father:=i;
    end;
  for i:=1 to m do
    begin
      read(c,c1);
      readln(j,k);
      x:=find(j);
      y:=find(k);
      if (c='A') then
        begin
          if (x=y) then
           writeln('In then same gang.')
          else
            begin
              if(a[x].diff=0) then
                writeln('Not sure yet.')
              else
                begin
                 if (find(a[x].diff)=y) then
                   writeln('In different gangs.')
                 else
                   writeln('Not sure yet.');
                end;
            end;
        end;
      if(c='D') then
        begin
          if (a[x].diff<>0) then
            hebing(find(a[x].diff),y);
          if (a[y].diff<>0) then
            hebing(find(a[y].diff),x);
          if (a[x].diff=0) then
            a[x].diff:=y;
          if (a[y].diff=0) then
            a[y].diff:=x;

         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