比赛 |
HAOI2009 模拟试题3 |
评测结果 |
AAAAA |
题目名称 |
医院设置 |
最终得分 |
100 |
用户昵称 |
.Xmz |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2009-04-23 08:43:30 |
显示代码纯文本
program xmz;
var
f1,f2:text;
a,n,b,ss,t1,t2:Longint;
f:array[1..100,1..100]of longint;
s:array[1..100]of longint;
min:int64;
procedure floyd;
var k,i,j:longint;
begin
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if f[i,j]>f[i,k]+f[k,j] then
f[i,j]:=f[i,k]+f[k,j];
end;
begin
assign(f1,'hospital.in');assign(f2,'hospital.out');
reset(f1);rewrite(f2);
read(f1,n);
for a:=1 to n do for b:=1 to n do f[a,b]:=9999999;
for a:=1 to n do
begin
read(f1,s[a],t1,t2);
if t1<>0 then begin f[t1,a]:=1;f[a,t1]:=1;end;
if t2<>0 then begin f[a,t2]:=1;f[t2,a]:=1;end;
end;
floyd;
min:=9999999999;
for a:=1 to n do
begin
for b:=1 to n do if a<>b then ss:=f[a,b]*s[b]+ss;
if ss<min then min:=ss;
ss:=0;
end;
if min=9999999999 then write(f2,0) else write(f2,min);
close(f1);close(f2);
end.