比赛 20120704 评测结果 WWWWWWWWWT
题目名称 危险游戏 最终得分 0
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2012-07-04 10:17:34
显示代码纯文本
var
  num1,num2,value,point,next:array[0..1000000]of longint;
  first:array[0..100000]of longint;
  n,m,i,x,y,total,z,q:longint;

procedure addpage(x,y,z:longint);
begin
  inc(total);
  point[total]:=y;
  value[total]:=z;
  next[total]:=first[x];
  first[x]:=total;
end;

procedure spfa;
var
  d,q:array[0..1000000]of longint;
  v:Array[0..10000]of boolean;
  ans,h,t,x,i,y:longint;
begin
  h:=1;
  t:=1;
  for i:=1 to n do v[i]:=false;
  for i:=1 to n do d[i]:=maxlongint div 2;
  d[1]:=0;
  v[1]:=true;
  q[1]:=1;
  repeat
    x:=q[h];
    i:=first[x];
    while i>0 do
    begin
      y:=point[i];
      if d[x]+value[i]<d[y] then
      begin
        d[y]:=d[x]+value[i];
        if not v[y] then
        begin
          v[y]:=true;
          inc(t);
          q[t]:=y;
        end;
      end;
      i:=next[i];
    end;
    v[x]:=false;
    inc(h);
  until h>t;
  ans:=0;
  for i:=1 to n do inc(ans,d[i]);
  writeln(ans);
end;

begin
  assign(input,'tubea.in'); reset(input);
  assign(output,'tubea.out'); rewrite(output);
  readln(n,m);
  for i:=1 to m do
  begin
    readln(x,y,z);
    addpage(x,y,z);
    num1[i]:=total;
    addpage(y,x,z);
    num2[i]:=total;
  end;
  spfa;
  readln(q);
  for i:=1 to q do
  begin
    readln(x,y);
    value[num1[x]]:=y;
    value[num2[x]]:=y;
    spfa;
  end;
  close(input);
  close(output);
end.