记录编号 22785 评测结果 AAAAAAAAAA
题目名称 最佳地点 最终得分 100
用户昵称 Gravatarybh 是否通过 通过
代码语言 Pascal 运行时间 1.090 s
提交时间 2010-12-25 12:43:11 内存使用 1.07 MiB
显示代码纯文本
{最佳地点
 最短路径
 Author: yangbohua
 Time: 2010-12-24}

program bestspot;
var
  map:array[0..501,0..501] of longint;
  v:Array[0..501] of longint;
  n,n1,m,i,j,k,r1,r2,r3,min,ans,sum:longint;
begin
  assign(input,'bestspot.in');
  reset(input);
  assign(output,'bestspot.out');
  rewrite(output);
  readln(n,n1,m);
  for i:=1 to n1 do
    readln(v[i]);
  for i:=1 to m do
  begin
    readln(r1,r2,r3);
    map[r1,r2]:=r3;
    map[r2,r1]:=r3;
  end;
  for k:=1 to n do
    for i:=1 to n do
      for j:=1 to n do
        if (i<>j) and (map[i,k]>0) and (map[k,j]>0) and ((map[i,k]+map[k,j]<map[i,j]) or (map[i,j]=0))
          then map[i,j]:=map[i,k]+map[k,j];
  min:=maxlongint;
  for i:=1 to n do
  begin
    sum:=0;
    for j:=1 to n1 do
      if i<>v[j] then
      begin
        if map[i,v[j]]>0
          then sum:=sum+map[i,v[j]]
          else
          begin
            sum:=maxlongint;
            break;
          end;
      end;
    if sum<min then
    begin
      min:=sum;
      ans:=i;
    end;
  end;
  writeln(ans);
  close(input);
  close(output);
end.