比赛 NOIP模拟赛by mzx Day1 评测结果 AAAAAAATTT
题目名称 零食店 最终得分 70
用户昵称 Sky_miner 运行时间 3.084 s
代码语言 C++ 内存使用 206.33 MiB
提交时间 2016-10-19 21:09:10
显示代码纯文本
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
	x=0;char ch;bool flag = false;
	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = 128;
const int maxm = 10000010;
int w[maxn],n,q;
int dis[maxn][maxn],num1[maxm],num2[maxm],s[maxm];
int lim_val[maxm],lim_dis[maxm],ans[maxm];
inline bool cmp(const int &i,const int &j){return w[i] < w[j];}
inline bool kmp(const int &i,const int &j){return lim_val[i] < lim_val[j];}
void work2(){
	int sy,sk,p = 1;
	for(int i=1;i<=q;++i){
		sk = num2[i];
		while(p <= n && w[ num1[p] ] <= lim_val[sk]){
			sy = num1[p];
			for(int j=1;j<=n;++j){
				for(int k=1;k<=n;++k){
					dis[j][k] = cat_min(dis[j][k],dis[j][sy]+dis[sy][k]);
				}
			}++p;
		}
		for(int j=1;j<=n;++j){
			if(j != s[sk] && dis[s[sk]][j]<=lim_dis[sk]) ++ans[sk];
		}
	}
}
int main(){
	freopen("snackstore.in","r",stdin);
	freopen("snackstore.out","w",stdout);
	memset(dis,0x3f,sizeof dis);
	int m;read(n);read(m);read(q);
	for(int i=1;i<=n;++i) read(w[i]),dis[i][i] = 0,num1[i] = i;
	for(int i=1,u,v,d;i<=m;++i){
		read(u);read(v);read(d);
		if(d < dis[u][v]) dis[u][v] = dis[v][u] = d;
	}
	int u,len,up;
	for(int i=1;i<=q;++i){
		read(s[i]);read(lim_val[i]);read(lim_dis[i]);
		num2[i] = i;
	}
	sort(num1+1,num1+n+1,cmp);
	sort(num2+1,num2+q+1,kmp);
	work2();
	for(int i=1;i<=q;++i) printf("%d\n",ans[i]);
	//getchar();getchar();
	fclose(stdin);fclose(stdout);
	return 0;
}