Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:大牛来帮忙看看,bellman-ford为什么会waIn Reply To:大牛来帮忙看看,bellman-ford为什么会wa Posted by:mountain_fly at 2010-11-14 15:31:00 > 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator