POJ2394 Checking an Alibi ——最短路——Pku2394
2011-09-02 20:56
369 查看
单源最短路的SPFA算法即可。
CODE
CODE
Program Alibi; Const maxn=1000; Var i,j,k,m,n,f,p,c,o,r,d :Longint; pre,other,last,dist,data :Array[1..maxn*2]of Longint; ans,place :Array[1..maxn]of Longint; Procedure Spfa; var seq :Array[1..maxn*10]of Longint; h,t :Longint; begin h:=0;t:=1;seq[1]:=1; fillchar(dist,sizeof(dist),127); dist[1]:=0; while h<t do begin inc(h); i:=seq[h]; j:=last[i]; while j<>0 do begin k:=other[j]; if dist[k]>dist[i]+data[j] then begin inc(t);seq[t]:=k; dist[k]:=dist[i]+data[j]; end; j:=pre[j]; end; end; end; BEGIN readln(f,p,c,m); for i:=1 to p do begin readln(o,r,d); inc(k);pre[k]:=last[o];last[o]:=k;other[k]:=r;data[k]:=d; inc(k);pre[k]:=last[r];last[r]:=k;other[k]:=o;data[k]:=d; end; Spfa; k:=0; for i:=1 to c do readln(place[i]); for i:=1 to c do if dist[place[i]]<=m then begin inc(k); ans[k]:=i; end; writeln(k); for i:=1 to k do writeln(ans[i]); END.
相关文章推荐
- POJ2394 Checking an Alibi 基础最短路
- POJ2394 Checking an Alibi 最短路
- pku2394 Checking an Alibi
- POJ 2394 Checking an Alibi (最短路+Dijkstra)
- POJ 2394 Checking an Alibi(最短路)
- POJ 2394 Checking an Alibi 简单最短路
- POJ2394,Checking an Alibi,Dijkstra单源最短路
- POJ2394 Checking an Alibi ——最短路
- poj 2394 Checking an Alibi
- poj 2394 Checking an Alibi--(Dijkstra)
- POJ 2394 Checking an Alibi (dijkstra)
- POJ2394 Checking an Alibi【Dijkstra】
- POJ 2394 Checking an Alibi【SPFA】
- poj 2394 Checking an Alibi
- 【BZOJ】1681: [Usaco2005 Mar]Checking an Alibi 不在场的证明(spfa)
- bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明
- Checking an Alibi(最短路径 Dijkstra)
- bzoj1681[Usaco2005 Mar]Checking an Alibi 不在场的证明
- BZOJ1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明
- 【bzoj1689】[Usaco2005 Mar]Checking an Alibi 不在场的证明