比赛 HAOI2009 模拟试题3 评测结果 AAAAA
题目名称 医院设置 最终得分 100
用户昵称 LXYXYNT 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2009-04-23 09:43:56
显示代码纯文本
const
  inf='hospital.in';
  ouf='hospital.out';
  maxn=100;
var
  a:array[1..maxn,1..maxn]of longint;
  b:array[1..maxn]of longint;
  n,m,i,j,k,y,x,z:longint;
begin
  assign(input,inf);reset(input);
  assign(output,ouf);rewrite(output);
  readln(n);
  for i:=1 to n do
   for j:=1 to n do
    a[i,j]:=99999;
  for i:=1 to n do a[i,i]:=0;
  for i:=1 to n do
  begin
    readln(b[i],y,z);
    if y<>0 then
    begin
      a[i,y]:=1;
      a[y,i]:=1;
    end;
    if z<>0 then
    begin
      a[i,z]:=1;
      a[z,i]:=1;
    end;
  end;
  for k:=1 to n do
   for i:=1 to n do
    for j:=1 to n do
     if (i-k)*(j-k)*(i-j)<>0 then
      if a[i,k]+a[k,j]<a[i,j] then a[i,j]:=a[i,k]+a[k,j];
  m:=maxlongint;
  for i:=1 to n do
  begin
    z:=0;
    for j:=1 to n do inc(z,b[j]*a[i,j]);
    if m>z then m:=z;
  end;
  writeln(m);
  close(input);
  close(output);
end.