请帮忙看下!为什么2,3个点wa?

type edge=record
u,v,c:longint;
end;
var
n,m,s,i:longint;
e:array[1..100000] of edge;
d:array[1..1000] of longint;
procedure init;
var
i,a,b:longint;
begin
read(n,m,s);
for i:=1 to m do
with e[i] do
read(u,v,c);
end;
function relaxed(u,v,c:longint):boolean;
begin
if (d[u]<>maxlongint)and(d[v]>d[u]+c)then
begin
d[v]:=d[u]+c;
exit(true);
end;
exit(false);
end;
function bellmanford(s:longint):boolean;
var
k,i:longint;
flag:boolean;
begin
for i:=1 to n do
d[i]:=maxlongint;
d[s]:=0;
for k:=1 to n-1 do
begin
flag:=false;
for i:=1 to m do
if relaxed(e[i].u,e[i].v,e[i].c) then flag:=true;
if not flag then break;
end;
for i:=1 to m do
if relaxed(e[i].u,e[i].v,e[i].c) then exit(false);
exit(true);
end;
begin
init;
if not bellmanford(s) then writeln('-1')
else
begin
for i:=1 to n do
if d[i]=maxlongint then writeln('NoPath')
else writeln(d[i]);
end;
end.

0 条评论

目前还没有评论...

信息

ID
1053
难度
8
分类
图结构 | 最短路 点击显示
标签
(无)
递交数
7505
已通过
678
通过率
9%
被复制
9
上传者