记录编号 26819 评测结果 AAAAAAAAA
题目名称 道路重建 最终得分 100
用户昵称 Gravatar老虎小飞 是否通过 通过
代码语言 Pascal 运行时间 0.041 s
提交时间 2011-07-27 15:31:10 内存使用 0.19 MiB
显示代码纯文本
const
  mm=200000000;
var
map:array[0..100,0..100]of int64;
n,m,i,j,x,y,k:longint;

function min(a,b:longint):longint;
begin
    if a>b then min:=b
    else min:=a;
end;

begin
    assign(input,'rebuild.in');reset(input);
    assign(output,'rebuild.out');rewrite(output);
    read(n,m);
    for i:=1 to n do
        for j:=1 to n do  map[i,j]:=mm;
    for i:=1 to m do begin
        read(x,y);
        read(map[x,y]);
        map[y,x]:=map[x,y];
    end;
    read(m);
    for i:=1 to m do begin
        read(x,y);
        if map[x,y]>0 then begin
            map[x,y]:=-map[x,y];
            map[y,x]:=-map[y,x];
        end;
    end;
    for i:=1 to n do
       for j:=1 to n do  begin
          if map[i,j]<>mm then begin
              if map[i,j]>=0 then map[i,j]:=0
              else map[i,j]:=-map[i,j];
          end;
          if i=j then map[i,j]:=0;
       end;
    for k:=1 to n do
       for i:=1 to n do
          for j:=1 to n do begin
             if map[i,j]>map[i,k]+map[k,j] then begin
             map[i,j]:=map[i,k]+map[k,j];
             end;
          end;
    read(x,y);
    writeln(map[x,y]);
    close(input);close(output);
end.