pascal FPC2.6.4的216错误
发布网友
发布时间:2024-09-29 00:08
我来回答
共2个回答
热心网友
时间:2024-11-15 08:48
这个程序的数组开得有点大,如下的程序在运行原数据时就能正常通过:
const max=22000;
var map:array [1..max,1..max] of longint;
n,m,i,a,b,t,ans,min,j,pos:longint;
dist:array [1..max] of longint;
flag:array [1..max] of 0..1;
begin
readln(n,m);
for i:=1 to m do
begin
readln(a,b,t);
map[a,b]:=t;
map[b,a]:=t;
end;
for i:=1 to n do
begin
if map[1,i]=0 then dist[i]:=4097 else dist[i]:=map[1,i];
end;
flag[1]:=1;
for i:=1 to n do
begin
min:=4097;
for j:=1 to n do
begin
if (flag[j]=0) and (dist[j]<min) then
begin
min:=dist[j];
pos:=j;
end;
end;
flag[pos]:=1;
for j:=1 to n do
begin
if (flag[j]=0) and (dist[pos]+map[pos,j]<dist[j]) then
begin
dist[j]:=dist[pos]+map[pos,j];
end;
end;
end;
writeln(dist[n]);
end.
5 3
1 4 5
4 5 1
1 2 7
热心网友
时间:2024-11-15 08:48
性
案件后公司的的哈u树杜哈德互杀