比赛 NOIP模拟赛by mzx Day1 评测结果 AAAATTTTTT
题目名称 零食店 最终得分 40
用户昵称 可以的. 运行时间 6.011 s
代码语言 C++ 内存使用 0.47 MiB
提交时间 2016-10-19 21:46:57
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <deque>
#define Mem(a,v) memset(a,v,sizeof(a))
using namespace std;
/*
freopen(".in","r",stdin);
	freopen(".out","w",stdout);
getchar(); getchar();
	return 0;
*/
#define maxn 110
void read(int &res){
	int x,f=1; char ch;
	while(ch=getchar(),ch<'0'||ch>'9')if(ch=='-')f=-1;
	x = ch - 48;
	while(ch=getchar(),ch>='0'&&ch<='9')x=x*10+ch-48;
	res = x * f;	
}
int N,M,Q,dis[maxn][maxn],v[maxn],len,head[maxn];
bool vis[maxn],ufs[maxn];
struct Edge
{
	int to,next,dis;
}e[10010<<1];

void insert(int x,int y,int z){
	e[++len].to = y;  e[len].dis = z;
	e[len].next = head[x]; head[x] = len;	
}
void Read(){
	read(N); read(M); read(Q);
	for(int i=1;i<=N;i++)read(v[i]);
	for(int i=1;i<=M;i++){
		int x,y,z;read(x);read(y);read(z);	
		insert(x,y,z); insert(y,x,z);
	}	
}
int ans = 0;

void Dfs(int x,int c,int tot){
	//printf("x = %d\n",x);
	//ans = max(ans , cnt);
	for(int i=head[x];i;i=e[i].next){
		int p = e[i].to;
		if(!vis[p] && tot-e[i].dis >= 0 && v[x] <= c){
			if(!ufs[p]){ ufs[p] = 1; ans++; }
			vis[p] = 1;
			Dfs(p,c,tot-e[i].dis);
			vis[p] = 0;
		}	
	}
}
void Ques(){
	while( Q -- ){
		ans = 0;
		int s,c,d,temp; read(s); read(c); read(d);
		Mem(vis,0);  Mem(ufs,0);  temp = v[s];  v[s] = -1;
		vis[s] = 1; ufs[s] = 1;
		Dfs(s , c , d);
		v[s] = temp;
		printf("%d\n",ans);
	}
}
int main(){
	freopen("snackstore.in","r",stdin);
	freopen("snackstore.out","w",stdout);
	
	Read();	
	Ques();
	
//	getchar(); getchar();
	return 0;
}