比赛 |
NOIP模拟赛by mzx Day1 |
评测结果 |
AAAATTTTTT |
题目名称 |
零食店 |
最终得分 |
40 |
用户昵称 |
安呐一条小咸鱼。 |
运行时间 |
6.012 s |
代码语言 |
C++ |
内存使用 |
0.85 MiB |
提交时间 |
2016-10-19 21:36:18 |
显示代码纯文本
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 100 + 10;
const int maxm = 20000 + 10;
int n,m,Q,vis[maxn],head[maxm],v[maxn],dis[maxn],tot,x,y,z,s,d,c,ret;
struct Edge{
int to,next,dis;
}edge[maxm<<1];
struct Node{
int id,dis,maxw;
Node(int a=0,int b=0,int c=0){
id=a,dis=b,maxw=c;
}
bool operator <(const Node & x)const
{
return dis>x.dis;
}
};
void Addedge(int x,int y,int z){
edge[++tot].to=y;
edge[tot].dis=z;
edge[tot].next=head[x];
head[x]=tot;
}
priority_queue<Node> q;
void Djs()
{
memset(vis,0,sizeof(vis));
int ret = 0 ;
q.push(Node(s,0,c));
vis[s]=1;
while(!q.empty())
{
Node t = q.top() ; q.pop();
for(int i=head[t.id];i;i=edge[i].next)
{
int p=edge[i].to;
if( t.dis + edge[i].dis > d )continue;
if( v[p] > t.maxw ){ if(!vis[p]){vis[p]=1;ret++;} continue; }
q.push(Node(p,t.dis+edge[i].dis,t.maxw));
if(!vis[p]){vis[p]=1;++ret;}
}
}
printf("%d\n",ret);
}
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",&v[i]);}
for(int i=1;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
Addedge(x,y,z); Addedge(y,x,z);
}
while(Q--)
{
scanf("%d%d%d",&s,&c,&d);
while(!q.empty())q.pop();
Djs();
}
//system("pause");
}
/*
int n,m,Q,v[maxn],head[maxm],tot,x,y,z,s,d,t,ret;
int dis[maxn][maxn],cnt[maxn][maxn],timark;
vector<int> work;
struct Edge{
int to,next,dis;
}edge[maxm<<1];
struct Node{
int s,d,w,ans;
int id,dis,maxw;
Node(int a=0,int b=0,int c=0)
{
id=a,dis=b,maxw=c;
}
bool operator <(const Node & x)const
{
return dis<x.dis;
}
}q[1000010];
bool cmp(const Node& x,const Node& y)
{
if(x.s!=y.s)return x.s<y.s;
else{
if(x.w!=y.w)return x.w<y.w;
else return x.d<y.d;
}
}
void Addedge(int x,int y,int z){
edge[++tot].to=y;
edge[tot].dis=z;
edge[tot].next=head[x];
head[x]=tot;
}
priority_queue<Node> p;
void Djs()
{
int size = work.size();
while(!p.empty())p.pop();
// *max min de zai qian mian
for(int i=0;i<size;i++)
{
t = work[i] , ret = 0;;
p.push(Node(q[t].s,q[t].d,q[t].w));
while(!p.empty())
{
Node node = p.top(); p.pop() ;
if(node.dis!=dis[q[t].s][node.id])continue;
if( cnt[q[t].s][node.id] >= timark )continue;
for(int e=head[node.id];e;e=edge[i].next)
{
int u = edge[i].to ;
if( v[u] > node.maxw )continue;
if( edge[i].dis > node.dis )continue;
cnt[q[t].s][node.id]++;ret++;
p.push(Node(u,node.dis-edge[i].dis,node.maxw));
}
}
q[t].ans = ret;
}
}
int main(){
scanf("%d%d%d",&n,&m,&Q);
for(int i=1;i<=n;i++){ scanf("%d",&v[i]);}
for(int i=1;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
Addedge(x,y,z);Addedge(y,x,z);
}
for(int i=1;i<=Q;i++){scanf("%d%d%d",&q[i].s,&q[i].d,&q[i].w);q[i].id=i;}
std::sort(q+1,q+1+Q,cmp);
for(int i=1;i<=Q;i++)
{
if(q[i].s==q[i+1].s)
{
work.push_back(i);
}
else{
work.push_back(i);
timark++;
Djs();
work.clear();
}
}
for(int i=1;i<=Q;i++)
{
printf("%d\n",q[i].ans);
}
}*/