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

难道pascal 就是慢 hk算法都要110ms

Posted by 513399730 at 2014-01-26 09:32:24 on Problem 3041
program hk;
var
  bh,d,l,h,q,pp:array[0..1000000]of longint;
  //b:array[0..1000000]of boolean;
  x,y,n,mm,i,s,k:longint;
procedure be;
  begin
    assign(input,'3041.in');
    assign(output,'3041.out');
    reset(input);
    rewrite(output);
  end;
procedure en;
  begin
    close(input);
    close(output);
  end;
procedure make(x,y:longint);
  begin
    inc(mm);
    h[mm]:=y;
    q[mm]:=l[x];
    l[x]:=mm;
  end;
function bfs :boolean;
  var
    t,w,i,x,s1,y:longint;
  begin
    bfs:=false;
    //fillchar(dx,sizeof(dx),0);
    fillchar(bh,sizeof(bh),0);
    t:=1;
    w:=0;
    for i:=1 to n do
      if pp[i]=-1 then
        begin
          inc(w);
          d[w]:=i;
        end;
    if w>0 then
    repeat
      x:=d[t];
      s1:=l[x];
      while s1>0 do
        begin
          y:=h[s1];
          if bh[y]=0 then
            begin
              bh[y]:=bh[x]+1;
              if pp[y]=-1 then
                bfs:=true else
                begin
                  bh[pp[y]]:=bh[y]+1;
                  inc(w);
                  d[w]:=pp[y];
                end;
            end;
          s1:=q[s1];
        end;
      inc(t);
    until t>w;
  end;
function dfs(x:longint):boolean;
  var
    s1,y:longint;
  begin
    dfs:=false;
    s1:=l[x];
    while s1>0 do
      begin
        y:=h[s1];
        if bh[y]=bh[x]+1 then
          begin
            bh[y]:=0;
            if (pp[y]=-1)or dfs(pp[y]) then
              begin
                pp[y]:=x;
                pp[x]:=y;
                exit(true);
              end;
          end;
        s1:=q[s1];
      end;
  end;

begin
//be;

  readln(n,k);
  mm:=0;
  for i:=1 to k do
    begin
      readln(x,y);
      inc(y,n);
      make(x,y);
      make(y,x);
    end;
  s:=0;
  fillchar(pp,sizeof(pp),255);
  //fillchar(ppy,sizeof(ppy),255);
  while bfs do
    begin
      for i:=1 to n do
        if (pp[i]=-1)and(dfs(i)) then
          inc(s);

    end;

  writeln(s);

//en;
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