比赛 |
20120710 |
评测结果 |
AATTA |
题目名称 |
RCDH外星人 |
最终得分 |
60 |
用户昵称 |
SnowDancer |
运行时间 |
2.002 s |
代码语言 |
Pascal |
内存使用 |
5.23 MiB |
提交时间 |
2012-07-10 11:43:00 |
显示代码纯文本
program et;
type
point=^node;
node=record x,w:longint;next:point; end;
var
n,i,j,k,l,m,now,last,head,tail,ans:longint;
code:array[1..30000] of longint;
dis,q:array[1..30000] of longint;
id:array[1..10,0..30000] of longint;
nodes:array[1..300000] of node;
h:array[1..30000] of point;
inq:array[1..30000] of boolean;
top,p:point;
procedure insertE(i,j,k:longint);
begin
top^.x:=j;top^.w:=k;
top^.next:=h[i];h[i]:=top;
inc(top);
end;
procedure SPFA(s:longint);
var
i:longint;
begin
for i:=1 to n do begin
dis[i]:=maxlongint>>2;
inq[i]:=false;
end;
dis[s]:=0;inq[s]:=true;q[1]:=s;
head:=0; tail:=1;
repeat
head:=head mod n+1;
p:=h[q[head]]; inq[q[head]]:=false;
while p<>nil do begin
if dis[p^.x]>p^.w+dis[q[head]] then begin
dis[p^.x]:=p^.w+dis[q[head]];
if not inq[p^.x] then begin
tail:=tail mod n+1;
q[tail]:=p^.x;
inq[p^.x]:=true;
end;
end;
p:=p^.next;
end;
until head=tail;
end;
begin
assign(input,'et.in');reset(input);
assign(output,'et.out');rewrite(output);
readln(n,m); top:=@nodes[1];
for i:=1 to n do begin
readln(code[i]);
inc(id[code[i],0]);
id[code[i]][id[code[i],0]]:=i;
end;
for l:=1 to m do begin
readln(i,j,k);
insertE(i,j,k);
insertE(j,i,k);
end;
for i:=1 to n do begin
SPFA(i);
now:=maxlongint;last:=maxlongint;
for j:=10 downto 1 do begin
for k:=1 to id[j,0] do begin
if dis[id[j,k]]<now then
now:=dis[id[j,k]];
if dis[id[j,k]]<last then inc(ans);
end;
last:=now;
end;
end;
writeln(ans);
close(input);close(output);
end.