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 |
超时求帮助..QQ:942225131program 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator