比赛 20120710 评测结果 AATTA
题目名称 RCDH外星人 最终得分 60
用户昵称 isabella 运行时间 2.003 s
代码语言 Pascal 内存使用 4.43 MiB
提交时间 2012-07-10 11:30:55
显示代码纯文本
var
 r:array[1..10,0..30000]of longint;
 map,w:array[1..30000,0..11]of longint;
 rr:array[1..30000]of longint;
 a,d:array[1..30000]of longint;
 v:array[1..30000]of boolean;
 n,m,k,i,j,x,y,t,dd,head,tail,ans,dt:longint;

 function min(a,b:longint):longint;
  begin if a<b then exit(a) else exit(b);end;

 procedure spfa(k:longint);
  var i:longint;
  begin
   fillchar(v,sizeof(v),0);
   fillchar(d,sizeof(d),$7f);d[k]:=0;

   head:=0;tail:=1;a[1]:=k;
   v[k]:=true;

 repeat
  head:=(head mod n)+1;
  x:=a[head];
  for i:=1 to map[x,0] do
   if (d[map[x,i]]>d[x]+w[x,i])then
    begin
      d[map[x,i]]:=d[x]+w[x,i];
      if v[map[x,i]]=false then
        begin v[map[x,i]]:=true;tail:=(tail mod n)+1;a[tail]:=map[x,i];end;
    end;
  v[x]:=false;
 until head=tail;
  end;

begin
assign(input,'et.in');reset(input);
assign(output,'et.out');rewrite(output);
 readln(n,m);
 for i:=1 to n do
  begin
   readln(k);rr[i]:=k;inc(r[k,0]);r[k,r[k,0]]:=i;
  end;
 for i:=1 to m do
  begin
   read(x,y,t);inc(map[x,0]);map[x,map[x,0]]:=y;w[x,map[x,0]]:=t;
   inc(map[y,0]);map[y,map[y,0]]:=x;w[y,map[y,0]]:=t;
  end;

 ans:=0;
 for i:=1 to n do
  begin

   t:=0;dd:=maxlongint;
   spfa(i);
   for j:=10downto rr[i] do
   begin
    dt:=dd;
    for k:=1 to r[j,0] do
     begin
      if d[r[j,k]]<dt then begin inc(t);dd:=min(dd,d[r[j,k]]);end;
     end;
   end;

   inc(ans,t);
  end;
 writeln(ans);
close(input);close(output);
end.