还是水题,接近于裸的spfa(个人比较喜欢用spfa,dijkstra不太喜欢用),代码附上
const maxn=;
type
link=^node;
node=record
t,d:longint;
f:link;
end;
var n,m,s,i,j,u,v,w,max:longint;
adj:array[..] of link;
f:array[..] of longint;
d,val:array[..] of longint;
went:array[..] of boolean;
procedure insert(f,t,d:longint);
var p:link;
begin
new(p);
p^.f:=adj[f];
p^.t:=t;
p^.d:=d;
adj[f]:=p;
end;
procedure spfa(s:longint);
var l,r,now,i:longint;
p:link;
begin
for i:= to n do
d[i]:=maxn;
fillchar(went,sizeof(went),true);
l:=; r:=; f[]:=s; d[s]:=; went[s]:=false;
while l<=r do
begin
now:=f[l];
p:=adj[now];
while p<>nil do
begin
if d[p^.t]>d[now]+p^.d then
begin
d[p^.t]:=d[now]+p^.d;
if went[p^.t] then
begin
went[p^.t]:=false;
inc(r);
f[r]:=p^.t;
end;
end;
p:=p^.f;
end;
went[now]:=true;
inc(l);
end;
end;
begin
readln(n,m,s);
for i:= to m do
begin
readln(u,v,w);
insert(u,v,w);
//insert(v,u,w);
end;
for i:= to n do
begin
spfa(i);
val[i]:=d[s];
//writeln(sb);
//writeln(d[s]);
end;
spfa(s);
for i:= to n do
//if i<>s then
begin
inc(val[i],d[i]);
if val[i]>max then max:=val[i];
end;
writeln(max);
end.
(转载请注明出处:http://www.cnblogs.com/Kalenda/)