比赛 NOIP模拟赛by mzx Day1 评测结果 AAAWWWWTTT
题目名称 零食店 最终得分 30
用户昵称 Yuri 运行时间 3.333 s
代码语言 C++ 内存使用 3.91 MiB
提交时间 2016-10-19 21:37:41
显示代码纯文本
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define cg ch=getchar()
#define maxn 110
#define LL long long

int tot, head[maxn];
LL dis[maxn];
LL ans, c[maxn];
LL vi[maxn];
LL s, C, D, cnt;

LL read(){
	LL res = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-') f = -1;cg;}
	while(ch >= '0' && ch <= '9'){res = res*10+ch-'0';cg;}
	return res*f;
}

struct Edge{
	LL to, nx, w;
}e[200010];

void edge(LL u,LL v,LL w){
	e[++tot].to = v;
	e[tot].w = w;
	e[tot].nx = head[u];
	head[u] = tot;
}

struct node{
	LL id, dist;
	node(LL x,LL y){id = x;dist = y;}
	bool operator < (const node& x) const {
		return dist > x.dist;
	}
};

void djs(LL u){
	priority_queue <node> q;q.push(node(u, 0));
	memset(dis, 127/3, sizeof(dis));dis[u] = 0;
	while(!q.empty()){
		node tmp = q.top();q.pop();
		LL x = tmp.id;
		if(dis[x] != tmp.dist) continue;
		for(int i = head[x];i;i = e[i].nx){
			LL to = e[i].to;
			if(to == u) continue;
			if(dis[to] > dis[x]+e[i].w){
				dis[to] = dis[x]+e[i].w;
				if(dis[to] > D)continue;
				if(c[to] > C){ans++;continue;}
				q.push(node(to, dis[to]));
				if(vi[to] != cnt){
					ans ++;
					vi[to] == cnt;
				}
			}
		}
	}
}

int main(){
	freopen("snackstore.in","r",stdin);
	freopen("snackstore.out","w",stdout);
	LL n = read(), m = read(), q = read();
	for(int i = 1;i <= n;i ++) c[i] = read();
	for(int i = 1,a,b,c;i <= m;i ++){
		a = read();b = read();c = read();
		edge(a,b,c);edge(b,a,c);
	}
	for(int i = 1;i <= q;i ++){
		s = read();C = read();D = read();
		ans = 0;
		cnt ++;
		djs(s);
		printf("%lld\n",ans);
	}
//	getchar();getchar();
	fclose(stdin);fclose(stdout);
	return 0;
}