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 |
我的为什么错了?求大牛帮助var q,dist,jd:array[1..500]of longint; cost,cd:array[1..500,1..500]of longint; v:array[1..500]of boolean; qqq,i,j,h,t,x,n,a,b,m,k,l,g,w:longint; qq:boolean; procedure spfa; begin fillchar(q,sizeof(q),0); h:=0; t:=0; fillchar(v,sizeof(v),false); fillchar(jd,sizeof(jd),0); for i:=1 to n do dist[i]:=maxint; inc(t); q[t]:=qqq; v[qqq]:=true; jd[qqq]:=1; dist[qqq]:=0; while h<>t do begin h:=(h mod n)+1; x:=q[h]; v[x]:=false; for i:=1 to n do begin if (cost[x,i]<>0) and (dist[x]+cost[x,i]<dist[i]) then begin dist[i]:=dist[x]+cost[x,i]; if not(v[i]) then begin t:=(t mod n)+1; q[t]:=i; jd[i]:=jd[i]+1; if jd[i]>n then begin qq:=true; exit; end; v[i]:=true; end; end; if (cd[x,i]<>0) and (dist[x]-cd[x,i]<dist[i]) then begin dist[i]:=dist[x]-cd[x,i]; if not(v[i]) then begin t:=(t mod n)+1; q[t]:=i; jd[i]:=jd[i]+1; if jd[i]>n then begin qq:=true; exit; end; v[i]:=true; end; end; end; end; end; begin read(m); for k:=1 to m do begin fillchar(cost,sizeof(cost),0); fillchar(cd,sizeof(jd),0); read(n,l,g); for i:=1 to l do begin read(a,b,w); if (cost[a,b]>w) or (cost[a,b]=0)then begin cost[a,b]:=w; cost[b,a]:=w; end; end; for i:=1 to g do begin read(a,b,w); if (cd[a,b]=0) or (cd[a,b]<w) then cd[a,b]:=w; end; qq:=false; for qqq:=1 to n do spfa; if qq 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