比赛 NOIP模拟赛by mzx Day1 评测结果 AAAAAAATTT
题目名称 零食店 最终得分 70
用户昵称 ONCE AGAIN 运行时间 3.899 s
代码语言 C++ 内存使用 0.54 MiB
提交时间 2016-10-19 21:44:29
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 110;
typedef long long LL;
LL dis[maxn] = {0};
int N,M,Q,a,b,c,T = 0,tot = 0,ans = 0;
int Flag[maxn] = {0},vis[maxn] = {0},head[maxn],w[maxn] = {0};
struct Link{int to,next,w;}link[20010];
struct Node{int id,dis;
	Node(int x,int y){
	 id = x;
	 dis = y;
	}
	bool operator<(const Node &a)const{
		return a.dis<dis;	
	}
};
void add(int from,int to,int w){
	link[++tot].to = to;
	link[tot].w = w;
	link[tot].next = head[from];
	head[from] = tot;	
}
priority_queue<Node> q;
void Dijkstra(){
	while(!q.empty())q.pop();
	memset(dis,0x3f,sizeof(dis));
	q.push(Node(a,0));
	dis[a] = 0;
	while(!q.empty()){
		Node D = q.top();
		q.pop();
		if(Flag[D.id] == T||vis[D.id] == T)continue;
		Flag[D.id] = T;
		for(int i = head[D.id];i;i=link[i].next){
			if(Flag[link[i].to]!=T&&dis[link[i].to]>dis[D.id]+link[i].w){
				dis[link[i].to] = dis[D.id]+link[i].w;
				q.push(Node(link[i].to,dis[link[i].to]));	
			}	
		}
	}	
	for(int i = 1;i<=N;i++)if(dis[i]<=c&&i!=a)ans++;
}
int main(){
	freopen("snackstore.in","r",stdin);
	freopen("snackstore.out","w",stdout);
	scanf("%d%d%d",&N,&M,&Q);
	for(int i = 1;i<=N;i++)scanf("%d",&w[i]);
	for(int i = 1;i<=M;i++){
		scanf("%d%d%d",&a,&b,&c);
		add(a,b,c);
		add(b,a,c);	
	}
	for(int i = 1;i<=Q;i++){
		scanf("%d%d%d",&a,&b,&c);
		T++;ans = 0;
		for(int j = 1;j<=N;j++)if(w[j]>b)vis[j] = T;
		vis[a] = T-1;
		Dijkstra();
		printf("%d\n",ans);
	}	
	return 0;
}