比赛 20110414pm 评测结果 AEATTTEEEE
题目名称 龙凡 最终得分 20
用户昵称 reamb 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-04-14 17:20:03
显示代码纯文本
program anquanlujing;
var
  l,dist,dist2:array[1..100000]of longint;
  biaozhi:array[1..100000]of boolean;
  q:array[1..100000]of longint;
  a,b,t,w,x,i,j,n,m,jilu:longint;
  map:array[1..4000,1..4000]of longint;
procedure preparation;
var
  i:longint;
begin
  for i:=1 to n do
    biaozhi[i]:=true;
  for i:=1 to n do
    dist[i]:=maxlongint;
  dist[1]:=0;
end;
procedure spfa;
begin
  q[1]:=1;
  biaozhi[1]:=false;
  t:=0;
  w:=1;
  while t<w do
  begin
    t:=t+1;
    x:=q[t];
    biaozhi[x]:=true;
    for i:=1 to n do
      if (map[x,i]>0)and(dist[x]+map[x,i]<dist[i]) then
      begin
        l[i]:=x;
        dist[i]:=dist[x]+map[x,i];
        if biaozhi[i] then
        begin
          biaozhi[i]:=false;
          w:=w+1;
          q[w]:=i
        end
      end
  end
end;
procedure spfa2;
var
  i:longint;
begin
  preparation;
  q[1]:=1;
  biaozhi[1]:=false;
  t:=0;
  w:=1;
  while t<w do
  begin
    t:=t+1;
    x:=q[t];
    biaozhi[x]:=true;
    for i:=1 to n do
      if (map[x,i]>0)and(dist2[x]+map[x,i]<dist2[i]) then
      begin
        dist2[i]:=dist2[x]+map[x,i];
        if biaozhi[i] then
        begin
          biaozhi[i]:=false;
          w:=w+1;
          q[w]:=i
        end
      end
  end
end;
begin
  assign (input,'travel.in');
  reset (input);
  assign (output,'travel.out');
  rewrite (output);
    readln (n,m);
    for i:=1 to m do
    begin
      readln (a,b,t);
      map[a,b]:=t;
      map[b,a]:=t
    end;
    preparation;
    spfa;
    for i:=2 to n do
    begin
      jilu:=map[i,l[i]];
      map[i,l[i]]:=0;
      map[l[i],i]:=0;
      for j:=2 to n do
        dist2[j]:=maxlongint;
      dist2[1]:=0;
      spfa2;
      if dist2[i]=maxlongint then
        writeln ('-1')
      else
        writeln (dist2[i]);
      map[i,l[i]]:=jilu;
      map[l[i],i]:=jilu
    end;
  close (input);
  close (output)
end.