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

超时求帮助..QQ:942225131

Posted by 942225131 at 2012-08-29 11:43:26 on Problem 3259
program poj3259;
var
  a:array[0..1000,0..1000]of longint;
  flag:array[0..1000]of boolean;
  c:array[0..100000]of longint;
  d:array[0..1000]of longint;
  f:array[0..1000]of longint;
  num,i,n:longint;
procedure init;
var
  i,m,w,s,e,x:longint;
begin
  fillchar(a,sizeof(a),$7f);
  readln(n,m,w);
  for i:=1 to m do
    begin
      readln(s,e,x);
      if a[s,e]>x then a[s,e]:=x;
      if a[e,s]>x then a[e,s]:=x;
    end;
  for i:=1 to w do
    begin
      readln(s,e,x);
      if a[s,e]>-x then a[s,e]:=-x;
    end;
end;
procedure spfa;
var
  i,j,l,r,k:longint;
begin
  fillchar(flag,sizeof(flag),false);
  fillchar(c,sizeof(c),0);
  fillchar(d,sizeof(d),$7f);
  fillchar(f,sizeof(f),0);
  l:=0; r:=1;
  d[1]:=0; c[1]:=1; f[1]:=1; flag[1]:=true;
  while l<r do
    begin
      inc(l);
      k:=c[l];
      for i:=1 to n do
        if d[i]>d[k]+a[k,i] then
          begin
            d[i]:=d[k]+a[k,i];
            if not flag[i] then
              begin
                inc(r);
                c[r]:=i;
                flag[i]:=true;
                inc(f[i]);
                if f[i]>=n then
                  begin writeln('YES'); exit; end;
              end;
          end;
      flag[k]:=false;
    end;
  writeln('NO');
end;
begin
  readln(num);
  for i:=1 to num do
    begin
      init;
      spfa;
    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