POJ2394 Checking an Alibi ——最短路——Pku2394

单源最短路的SPFA算法即可。

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.

转载于:https://www.cnblogs.com/Thispoet/archive/2011/09/02/2164342.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值