# 26991: 带负权的单源最短路

输入一个有向网络图，边的权值可正可负，求顶点到其他各点的最短路。

4
0 0 -3 0
2 0 0 0
0 -1 0 -4
0 0 0 0

not possible

program p26991;
var
w:array[0..1000,0..1000]of longint;
dist:array[0..1000]of longint;
n,x,i,j,k:longint;
change:boolean;
begin

for i:=0 to n-1 do
for j:=0 to n-1 do
begin
if (x=0)and(i<>j)then w[i,j]:=maxint else w[i,j]:=x;
end;
for i:=1 to n do
if w[i,j]=maxint then dist[i]:=maxint else dist[i]:=w[0,i];
dist[0]:=0;
for k:=0 to n-1 do
for j:=0 to n-1 do
for i:=0 to n-1 do
if (w[i,j]<>maxint)and(dist[i]<>maxint)and(dist[j]>dist[i]+w[i,j])
then
dist[j]:=dist[i]+w[i,j];
change:=true;

for i:=0 to n-1 do
for j:=0 to n-1 do
if dist[j]>dist[i]+w[i,j]
then change:=false;
if not change then
writeln('not possible')
else
for i:=1 to n-2 do
write(dist[i],' ');
if change then
writeln(dist[n-1]);

end.

#### hdu1317 负权最短路（Floyd+bellman）

2016-07-24 12:45:50

#### bellman-ford算法——最短路问题，判断是否存在负权回路或正权回路

2015-11-09 10:37:51

#### poj3259（最短路+负权处理）

2015-03-11 20:19:52

#### POJ - 3259之时空穿梭(最短路之负权回路)

2017-07-25 19:25:09

#### 最短路之 SPFA（判环+负权）

2014-04-02 14:16:31

#### poj 2240（bellman_ford 算法）（最短路负权）Arbitrage

2016-07-13 23:34:13

#### Adventurous Driving - POJ 2679 最短路+负环

2015-06-02 20:41:44

#### 最短路（SPFA+负权回路的判断）-poj3268

2013-10-02 19:40:39

#### 最短路径(6)--poj3259(最短路应用-求负权回路)

2016-11-26 00:57:47

#### SPFA 求带负权的单源最短路

2015-03-12 20:48:50