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

为何WA

Posted by wdqwang1 at 2012-04-07 00:44:33 on Problem 2553
var a,aa:array[1..15000,1..2]of longint;
    b,d,bb,dd,f,color,ans:array[1..5005]of longint;
    ff:array[1..5001]of boolean;
    i,j,k,n,m,num,date,nn,mm:longint;
procedure qsort(s,t:longint);
var i,j,x,xx:longint;
begin
i:=s;j:=t;x:=a[(s+t) shr 1,1];xx:=a[(s+t) shr 1,2];
a[(s+t) shr 1]:=a[s];
repeat
while (i<j) and (a[j,1]>=x) do dec(j);
if j>i then a[i]:=a[j];
while (i<j) and (a[i,1]<=x) do inc(i);
if j>i then a[j]:=a[i];
until i=j;
a[i,1]:=x;a[i,2]:=xx;
inc(i);dec(j);
if i<t then qsort(i,t);
if j>s then qsort(s,j);
end;
procedure dfs(x:longint);
var i:longint;
begin
  color[x]:=1;
  for i:=b[x] to b[x+1]-1 do
    if color[a[i,2]]=0 then dfs(a[i,2]);
  color[x]:=2;
  inc(date);
  d[x]:=date;
end;
procedure dfs1(x:longint);
var i,j:longint;
begin
  f[x]:=nn;
  for i:=b[x] to b[x+1]-1 do
     if f[a[i,2]]=0 then dfs1(a[i,2]);
end;
procedure build;
var i,j:longint;
begin
 fillchar(b,sizeof(b),0);
 if m>1 then qsort(1,m);
 for i:=1 to m do
    if b[a[i,1]]=0 then b[a[i,1]]:=i;
 b[n+1]:=m+1;
 for i:=n downto 1 do
   if b[i]=0 then b[i]:=b[i+1];
end;
procedure main;
begin
 fillchar(d,sizeof(d),0);
 fillchar(color,sizeof(color),0);
 fillchar(f,sizeof(f),0);
 num:=0;
 for i:=1 to m do read(a[i,1],a[i,2]);
 build;
 date:=0;
 for i:=1 to n do
   if color[i]=0 then dfs(i);
 aa:=a;
 bb:=b;
 for i:=1 to m do
   begin
     k:=a[i,1];
     a[i,1]:=a[i,2];
     a[i,2]:=k;
   end;
 build;
 for i:=1 to n do
     dd[d[i]]:=i;
 nn:=0;mm:=0;
 for i:=n downto 1 do
      if f[dd[i]]=0 then
         begin
           inc(nn);
           dfs1(dd[i]);
         end;
 for i:=1 to n do
   for j:=bb[i] to bb[i+1]-1 do
      if f[aa[j,1]]<>f[aa[j,2]] then
          begin
               inc(mm);
               a[mm,1]:=f[aa[j,1]];
               a[mm,2]:=f[aa[j,2]];
          end;
 fillchar(b,sizeof(b),0);
 if mm>1 then qsort(1,mm);
 for i:=1 to mm do
    if b[a[i,1]]=0 then b[a[i,1]]:=i;
 fillchar(ff,sizeof(ff),false);
 for i:=1 to nn do
    if b[i]=0 then  ff[i]:=true;
 for i:=1 to n do
    if ff[f[i]] then
      begin
        inc(num);
        ans[num]:=i;
      end;
 for i:=1 to num-1 do write(ans[i],' ');
 writeln(ans[num]);
end;
begin
assign(input,'e:\a.in');
assign(output,'e:\a.out');
reset(input);
rewrite(output);
 read(n);
 while n<>0 do
   begin
      readln(m);
      main;
      read(n);
   end;
close(input);
close(output);
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