| 比赛 | 
    20110722 | 
    评测结果 | 
    AAAWAWAAAWAWAAAWA | 
    | 题目名称 | 
    网络探测 | 
    最终得分 | 
    70 | 
    | 用户昵称 | 
    reamb | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    Pascal | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2011-07-22 11:47:36 | 
显示代码纯文本
program wangluozhentan;
var
  dist:array[0..1000]of longint;
  map:array[0..1000,0..1000]of longint;
  bz:array[0..1000]of boolean;
  team:array[1..10000]of longint;
  i,x,y,z,n,m,tt:longint;
procedure spfa;
var
  t,w,k,d:longint;
begin
  for k:=1 to n do
  begin
    dist[k]:=maxlongint;
    bz[k]:=true
  end;
  dist[0]:=0;
  team[1]:=0;
  bz[0]:=false;
  t:=1;
  w:=1;
  while t<=k do
  begin
    d:=team[t];
    inc(t);
    bz[d]:=true;
    for k:=1 to n do
      if (map[d,k]<>0)and(dist[d]+map[d,k]<dist[k]) then
      begin
        dist[k]:=dist[d]+map[d,k];
        if bz[k] then
        begin
          inc(w);
          team[w]:=k;
          bz[k]:=false
        end
      end
  end
end;
begin
  assign (input,'ping.in');
  reset (input);
  assign (output,'ping.out');
  rewrite (output);
    readln (n,m,tt);
    for i:=1 to m do
    begin
      readln (x,y,z);
      if map[x,y]=0 then
      begin
        map[x,y]:=z;
        map[y,x]:=z
      end
      else
        if z<map[x,y] then
        begin
          map[x,y]:=z;
          map[y,x]:=z
        end
    end;
    spfa;
    if dist[tt]<>maxlongint then
      writeln (dist[tt])
    else
      writeln ('no');
  close (input);
  close (output)
end.