比赛 |
20120710 |
评测结果 |
WWTTW |
题目名称 |
RCDH外星人 |
最终得分 |
0 |
用户昵称 |
zhangchi |
运行时间 |
2.004 s |
代码语言 |
Pascal |
内存使用 |
12.32 MiB |
提交时间 |
2012-07-10 11:57:28 |
显示代码纯文本
type
node=record
v,w,next:longint;
end;
var
n,m,tot,i,j,temp,x,y,z,num,head,tail,p,ans,mm:longint;
d:array[1..30001] of longint;
q:array[0..30000] of boolean;
dis,last:array[0..30000] of longint;
f:array[0..30000] of longint;
a:array[1..1000000] of node;
rr,dr:array[0..30000] of longint;
function max(x,y:longint):longint;
begin if x>y then max:=x else max:=y; end;
procedure insert(x,y,z:longint);
begin
inc(tot);
a[tot].next:=f[x];
f[x]:=a[tot].next;
a[tot].v:=x;
a[tot].w:=z;
end;
procedure SPFA(x:longint);
begin
fillchar(dis,sizeof(dis),$7F div 2);
dis[x]:=0;
head:=0; tail:=1;
q[x]:=true;
d[1]:=x;
repeat
head:=head mod n+1;
temp:=d[head];
q[temp]:=false;
p:=f[temp];
while p<>0 do
begin
if dis[temp]+a[p].w<dis[a[p].v] then
begin
dis[a[p].v]:=dis[temp]+a[p].w;
if q[a[p].v]=false then
begin
q[a[p].v]:=true;
tail:=tail mod n+1;
d[tail]:=a[p].v;
end;
end;
p:=a[p].next;
end;
until head=tail;
end;
procedure sort(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l; j:=r;
m:=dis[(l+r) div 2];
repeat
while dis[i]<m do inc(i);
while dis[j]>m do dec(j);
if i<=j then
begin
t:=dis[i]; dis[i]:=dis[j]; dis[j]:=t;
t:=rr[i]; rr[i]:=rr[j]; rr[j]:=t;
inc(i); dec(j);
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;
begin
assign(input,'et.in'); reset(input);
assign(output,'et.out'); rewrite(output);
readln(n,m);
for i:=1 to n do
readln(rr[i]);
for i:=1 to m do
begin
readln(x,y,z);
insert(x,y,z);
insert(y,x,z);
end;
for i:=1 to n do
begin
SPFA(i);
dr:=rr;
sort(1,n);
mm:=rr[1];
inc(ans);
for j:=2 to n do
begin
mm:=max(mm,rr[j]);
if rr[j]<mm then continue;
ans:=ans+1;
end;
rr:=dr;
end;
writeln(ans);
close(input); close(output);
end.