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

大牛来帮忙看看,bellman-ford为什么会wa

Posted by mountain_fly at 2010-11-14 15:31:00 on Problem 3259
pascal的


program xxxxxx;
var
  n,w,m:longint;
  d:array[1..1000,1..1000]of longint;
  f:array[1..1000]of longint;
  i,j,k,a,b,t,bj,ff:longint;
  bb:boolean;
begin
  readln(ff);
  for k:=1 to ff do
  begin
    bb:=false;
    readln(n,m,w);
    for i:=1 to m do
    begin
      read(a,b,t);
      d[a,b]:=t;
      d[b,a]:=t;
    end;
    for i:=1 to w do
    begin
      read(a,b,t);
      d[a,b]:=-t;
    end;
    for i:=2 to n do f[i]:=d[1,i];
    for t:=1 to n-1 do
    begin
      bj:=0;
      for i:=1 to n do
      for j:=1 to n do
      if (i<>j)and(d[i,j]<>0)and(f[i]<>0) then
      if (d[i,j]+f[i]<f[j])or(f[j]=0) then
      begin
        bj:=1;
        f[j]:=f[i]+d[i,j];
      end;
      if bj=0 then break;
    end;
    for i:=1 to n do
    for j:=1 to n do
    if f[i]+d[i,j]<f[j] then bb:=true;
    if bb then writeln('YES') else writeln('NO');
  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