记录编号 17257 评测结果 AAAAA
题目名称 [HAOI 2005]希望小学 最终得分 100
用户昵称 GravatarAchilles 是否通过 通过
代码语言 Pascal 运行时间 0.003 s
提交时间 2010-07-17 12:17:15 内存使用 0.12 MiB
显示代码纯文本
program hopeschool;
var
  n,b1,b2,b3,g1,g2,g3,s1,s2,s3,a,b,i,j,k,t,min,mt:longint;
  x,y:array[1..40]of longint;
  tab:array[1..40,1..40,1..2]of longint;
begin
  assign(input,'hopeschool.in');
  assign(output,'hopeschool.out');
  reset(input);
  rewrite(output);
  readln(n,b2,b1,b3,g2,g1,g3);
  for i:=1 to n do
    read(x[i]);
  readln;
  for i:=1 to n do
    read(y[i]);
  readln(k);
  for i:=1 to n do
    for j:=1 to n do
    begin
      tab[i,j,1]:=-1;
      tab[i,j,2]:=-1;
    end;
  for i:=1 to k do
  begin
    readln(a,b,s2,s1,s3);
    tab[a,b,1]:=s1*b1+s2*b2+s3*b3;
    tab[a,b,2]:=s1*g1+s2*g2+s3*g3;
    tab[b,a,1]:=s1*b3+s2*b2+s3*b1;
    tab[b,a,2]:=s1*g3+s2*g2+s3*g1;
  end;
  for j:=1 to n do
    for i:=1 to n do
      for k:=1 to n do
      if (i<>j)and(j<>k)and(i<>k) then
        begin
          if (tab[i,j,1]<>-1)and(tab[j,k,1]<>-1) then
            if (tab[i,j,1]+tab[j,k,1]<tab[i,k,1])or(tab[i,k,1]=-1) then tab[i,k,1]:=tab[i,j,1]+tab[j,k,1];
          if (tab[i,j,2]<>-1)and(tab[j,k,2]<>-1) then
            if (tab[i,j,2]+tab[j,k,2]<tab[i,k,2])or(tab[i,k,2]=-1) then tab[i,k,2]:=tab[i,j,2]+tab[j,k,2];
        end;
  min:=2000000000;
  for i:=1 to n do
  begin
    mt:=0;
    for j:=1 to n do
      if i<>j then begin
        mt:=mt+tab[j,i,1]*x[j];
        mt:=mt+tab[j,i,2]*y[j];
      end;
    if mt<min then begin
      min:=mt;
      t:=i;
    end;
  end;
  writeln(t);
  close(input);
  close(output);
end.