比赛 NOIP模拟赛by mzx Day1 评测结果 MMMMMMMMMM
题目名称 零食店 最终得分 0
用户昵称 哒哒哒哒哒! 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2016-10-19 21:35:19
显示代码纯文本
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctime>
using namespace std;
#define ll long long
ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10+ch-48,ch=getchar();
	return x*f;
}
const ll maxn=120;
const ll maxm=10000010;
ll c[maxn],n,m,q;
ll dis[maxn][maxn],re1[maxn],re2[maxm];
ll ans[maxm],limv[maxm],limc[maxm],s[maxm];

bool cmp1(ll a,ll b){return c[a]<c[b];}
bool cmp2(ll a,ll b){return limc[a]<limc[b];}
void solve(){
	ll sx,sy,p=1;
	for(ll i=1;i<=q;i++){
		sx=re2[i];
		while(p<=n && c[re1[p]]<=limc[sx]){
			sy=re1[p];
			for(ll j=1;j<=n;j++){
				for(ll k=1;k<=n;k++){
					dis[j][k]=min(dis[j][k],dis[j][sy]+dis[sy][k]);
				}
			}
			p++;
		}
		for(ll j=1;j<=n;j++)
			if(j!=s[sx]&&dis[s[sx]][j]<=limv[sx]) ++ans[sx];
	}
}

int main(){
	freopen("snackstore.in","r",stdin);freopen("snackstore.out","w",stdout);
	memset(dis,0x3f,sizeof dis);
	n=read(),m=read(),q=read();
	for(ll i=1;i<=n;i++){
		c[i]=read(),dis[i][i]=0;
		re1[i]=i;
	}
	for(ll i=1;i<=m;i++){
		ll a=read(),b=read(),c=read();
		if(c<dis[a][b]) dis[a][b]=dis[b][a]=c;
	}
	for(ll i=1;i<=q;i++){
		s[i]=read(),limc[i]=read(),limv[i]=read();
		re2[i]=i;
	}
	sort(re1+1,re1+n+1,cmp1);
	sort(re2+1,re2+q+1,cmp2);
	solve();
	for(ll i=1;i<=q;i++)printf("%lld\n",ans[i]);
	fclose(stdin);fclose(stdout);
	return 0;
}