比赛 NOIP模拟赛by mzx Day1 评测结果 AAAAAAATTT
题目名称 零食店 最终得分 70
用户昵称 小怪兽 运行时间 3.705 s
代码语言 Pascal 内存使用 0.89 MiB
提交时间 2016-10-19 20:16:36
显示代码纯文本
type node=record
     u,v,c,q:longint;
     end;

var n,m,q,x,y,z,s,c,d,i,j,ans,tot:longint;
    lu:array[0..20100] of node;
    dist:array[0..101] of int64;
    h,xf:array[0..101] of longint;
    flag:array[0..101] of boolean;
    a:array[0..101,0..101] of longint;
    dl:array[1..100000] of longint;

procedure add(x,y,z:longint);
begin
inc(tot);
lu[tot].u:=x;lu[tot].v:=y;lu[tot].c:=z;
lu[tot].q:=h[x];h[x]:=tot;
a[x,y]:=z;
end;

function relax(t:longint):boolean;
var u,v:longint;
begin
u:=lu[t].u;v:=lu[t].v;
if dist[u]+lu[t].c<=dist[v] then
        begin
        dist[v]:=dist[u]+lu[t].c;
        exit(true);
        end;
exit(false);
end;

procedure spfa(s:longint);
var head,tail,next,x,y,i:longint;
begin
for i:=1 to n do dist[i]:=maxlongint;
dist[s]:=0;
head:=0;tail:=1;
dl[1]:=s;
flag[s]:=true;
repeat
inc(head);
x:=dl[head];
flag[x]:=false;
if (xf[x]>c)and(x<>s) then continue;
next:=h[x];
while next<>0 do
        begin
        y:=lu[next].v;
        if (relax(next))and(flag[y]=false) then
                begin
                inc(tail);
                dl[tail]:=y;
                flag[y]:=true;
                end;
        next:=lu[next].q;
        end;
until head>=tail;
end;

begin
assign(input,'snackstore.in');
assign(output,'snackstore.out');
reset(input);
rewrite(output);
read(n,m,q);
for i:=1 to n do read(xf[i]);
fillchar(a,sizeof(a),127);
for i:=1 to m do
        begin
        read(x,y,z);
        if a[x,y]>z then
                begin
                add(x,y,z);
                add(y,x,z);
                end;
        end;
for i:=1 to q do
        begin
        read(s,c,d);
        spfa(s);
        ans:=0;
        for j:=1 to n do if (dist[j]<=d)and(j<>s) then inc(ans);
        writeln(ans);
        end;
close(input);
close(output);
end.