比赛 NOIP模拟赛by mzx Day1 评测结果 AWAAWWWTTT
题目名称 零食店 最终得分 30
用户昵称 Cydiater 运行时间 3.513 s
代码语言 C++ 内存使用 53.88 MiB
提交时间 2016-10-19 21:04:42
显示代码纯文本
//B
//by Cydiater
//2016.10.19
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std;
#define ll long long
#define up(i,j,n)		for(int i=j;i<=n;i++)
#define down(i,j,n)		for(int i=j;i>=n;i--)
#define FILE "snackstore"
const int MAXN=1e6+5;
const int oo=0x3f3f3f3f;
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct Ask{
	int s,c,d,ans,id;
	Ask(){ans=0;}
}ask[MAXN];
struct edge{
	int x,y,next,v;
}e[MAXN];
struct Node{
	int id,c;
}node[MAXN];
int N,M,Q,f[205][205],LINK[MAXN],len=0,added=1,cnt[MAXN],C[MAXN];
namespace solution{
	inline void insert(int x,int y,int v){e[++len].next=LINK[x];LINK[x]=len;e[len].y=y;e[len].v=v;}
	inline bool cmp1(Ask x,Ask y){return x.c<y.c;}
	inline bool cmp2(Node x,Node y){return x.c<y.c;}
	inline bool cmp3(Ask x,Ask y){return x.id<y.id;}
	void init(){
		memset(f,10,sizeof(f));
		N=read();M=read();Q=read();
		up(i,1,N){node[i].c=read();node[i].id=i;C[i]=node[i].c;}
		up(i,1,M){
			int x=read(),y=read(),v=read();
			insert(x,y,v);
			insert(y,x,v);
			f[x][y]=min(f[x][y],v);
			f[y][x]=f[x][y];
		}
		up(i,1,Q){
			ask[i].s=read();ask[i].c=read();ask[i].d=read();ask[i].id=i;
		}
		sort(ask+1,ask+Q+1,cmp1);
		sort(node+1,node+N+1,cmp2);
	}
	void slove(){
		up(i,1,N)f[i][i]=0;
		up(i,1,Q){
			int c=ask[i].c,now=ask[i].s;bool flag=0;
			while(node[added].c<=c&&added<=N){
				int tmp=node[added].id;
				for(int h=LINK[tmp];h;h=e[h].next){
					f[tmp][e[h].y]=min(f[tmp][e[h].y],e[h].v);
					f[e[h].y][tmp]=f[tmp][e[h].y];
				}
				added++;flag=1;
			}
			if(flag){
				up(k,1,N)if(C[k]<=ask[i].c)up(m,1,N)up(n,1,N)
				if(f[m][k]+f[k][n]<f[n][m])f[n][m]=f[m][k]+f[n][k];
			}
			up(j,1,N)if(f[now][j]<=ask[i].d&&now!=j)cnt[j]=i;
			up(j,1,N)if(cnt[j]==i&&j!=now)ask[i].ans++;
		}
	}
	void output(){
		sort(ask+1,ask+Q+1,cmp3);
		up(i,1,Q)printf("%d\n",ask[i].ans);
	}
}
int main(){
	freopen(FILE".in","r",stdin);
	freopen(FILE".out","w",stdout);
	using namespace solution;
	init();
	slove();
	output();
	return 0;
}