求助!!!!

为什么这个错的,!!!!!!!!!

program P1746;
var i,j,k,n,m,x,y,q,u,o:longint;
v,w:array[0..10001] of longint;
a,f:array[0..501,0..501] of longint;

function min(x,y:longint):longint;
begin
if x>y then exit(y) else exit(x);
end;

procedure data;
var i,j,k:longint;
begin
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
a[j,k]:=min(a[j,k],a[j,i]+a[i,k]);
for i:=1 to n do
for j:=1 to n do
for k:=1 to n do
f[j,k]:=min(f[j,k],a[j,i]+a[i,k]+v[i]);
end;

procedure datain;
var i,j,u,o:longint;
begin
fillchar(a,sizeof(a),\(0f);
fillchar(f,sizeof(f),\)0f);
readln(n,m);
for i:=1 to n do
readln(v[i]);
for i:=1 to n do
a[i,i]:=0;
for i:=1 to m do
begin
readln(x,y,w[i]);
if a[x,y]>w[i] then
a[x,y]:=w[i];
a[y,x]:=w[i];
end;
readln(q);
data;
for i:=1 to q do
begin
readln(u,o);
if f[u,o]>100000000 then writeln(-1) else
writeln(f[u,o]);
end;
end;

begin
// data1;
datain;
// data2;
end.

5 条评论

  • @ 2014-10-30 18:55:49

    已经知道了,O(∩_∩)O谢谢

  • @ 2014-10-30 16:58:21

    ac了,n次枚举
    var
    f,g:array[1..800,1..800]of longint;
    a:array[1..800]of longint;
    n,m,i,j,k,x,y,z,l,r,ans,q:longint;
    begin
    readln(n,m);
    for i:=1 to n do for j:=1 to n do if i<>j then f[i,j]:=1000000000;
    for i:=1 to n do read(a[i]);
    for i:=1 to m do begin
    read(x,y,z);if z<f[x,y] then begin
    f[x,y]:=z;f[y,x]:=z;end;end;
    for k:=1 to n do for i:=1 to n do for j:=1 to n do
    if f[i,k]+f[k,j]<f[i,j] then begin
    f[i,j]:=f[i,k]+f[k,j];g[i,j]:=k;end;
    read(q);
    for i:=1 to q do
    begin
    read(x,y);ans:=1000000000;
    for j:=1 to n do if f[x,j]+f[j,y]+a[j]<ans then ans:=f[x,j]+f[j,y]+a[j];
    if ans<1000000000 then writeln(ans)else writeln(-1);
    end;
    end.

  • @ 2014-10-30 16:44:07

    var
    f,g:array[1..400,1..400]of longint;
    a:array[1..400]of longint;
    n,m,i,j,k,x,y,z,l,r,ans,q:longint;
    begin
    readln(n,m);
    for i:=1 to n do for j:=1 to n do f[i,j]:=1000000000;
    for i:=1 to n do read(a[i]);
    for i:=1 to m do begin
    read(x,y,z);if z<f[x,y] then begin
    f[x,y]:=z;f[y,x]:=z;end;end;
    for k:=1 to n do for i:=1 to n do for j:=1 to n do
    if f[i,k]+f[k,j]<f[i,j] then begin
    f[i,j]:=f[i,k]+f[k,j];g[i,j]:=k;end;
    read(q);
    for i:=1 to q do
    begin
    read(x,y);l:=x;r:=y;ans:=a[r];
    if f[x,y]=1000000000 then begin writeln(-1);continue;end;
    while g[l,r]<>0 do begin r:=g[l,r]; if a[r]<ans then ans:=a[r];end;
    if a[l]<ans then ans:=a[l];writeln(f[x,y]+ans);
    end;
    end.

  • @ 2014-10-30 12:30:42

    我也十分

  • @ 2014-10-30 11:31:22

    算法应该没有错误 我觉得应该是fillchar的问题或者是输出-1那句话的判断
    我初始化用两个for循环 赋一个固定的值比如123456 输出时就判断是否等于123456 如果等于就输出-1

    • @ 2014-10-30 14:49:26

      还是错的

    • @ 2014-10-30 19:36:09

      读入x,y,w[i],那里,少了begin end。。。那个a[y,x]:=w[i]没循环进去。。。:D

  • 1

信息

ID
1746
难度
5
分类
图结构 | 最短路 点击显示
标签
(无)
递交数
899
已通过
287
通过率
32%
被复制
3
上传者