比赛 20091103 评测结果 C
题目名称 热浪 最终得分 0
用户昵称 ybh 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-11-03 11:16:41
显示代码纯文本
program ReLang;
var
  way:array[0..2500,0..2500] of integer;
  cost:array[0..2500] of longint;
  n,m,te,ts,t,i,r1,r2,r3,mini:integer;
  min:longint;
  arrive:set of 0..2500;
begin
  assign(input,'heatwvx.in');
  reset(input);
  assign(output,'heatwvx.out');
  rewrite(output);
  readln(n,m,ts,te);
  fillchar(way,sizeof(way),0);
  fillchar(cost,sizeof(cost),0);
  for i:=1 to m do
  begin
    readln(r1,r2,r3);
    way[r1,r2]:=r3;
    way[r2,r1]:=r3
  end;
  arrive:=[ts];
  t:=ts;
  repeat
    for i:=1 to n do
    begin
      if way[t,i]>0 then
      begin
        if ((cost[t]+way[t,i]<cost[i]) or (cost[i]=0)) and ((i in arrive)=false) then
        begin
          cost[i]:=cost[t]+way[t,i];
        end
      end
    end;
    min:=maxlongint;
    for i:=1 to n do
      if ((i in arrive)=false) and (min>cost[i]) and (cost[i]>0) then
      begin
        min:=cost[i];
        mini:=i
      end;
    if min<maxlongint then
    begin
      arrive:=arrive+[mini];
      t:=mini;
    end
  until t=te;
  writeln(cost[te]);
  close(input);
  close(output)
end.