比赛 |
NOIP模拟赛by mzx Day1 |
评测结果 |
AAAAAAATTT |
题目名称 |
零食店 |
最终得分 |
70 |
用户昵称 |
YGOI_真神名曰驴蛋蛋 |
运行时间 |
3.288 s |
代码语言 |
C++ |
内存使用 |
19.66 MiB |
提交时间 |
2016-10-19 21:41:22 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
int read(){
int x=0,f=1; char ch;
while(ch=getchar(), !isdigit(ch)) if(ch=='-') f = -1;
x = ch-'0';
while(ch=getchar(), isdigit(ch)) x = x*10+ch-'0';
return x*f;
}
const int maxn = 105, maxm = 10005, maxq = 1000005;
struct Edge{
int next, to, dis;
Edge(int a=0, int b=0, int c=0):next(a), to(b), dis(c){}
}e[maxm<<1];
int head[maxn], tot;
void Add(int u, int v, int w) {
e[++tot] = Edge(head[u], v, w); head[u] = tot;
}
int M, N, Q;
int v[maxn], s, liv, lid;
/*================================================================*/
struct Que{
int s, liv, lid, id;
bool operator < (const Que& x) const {
return liv < x.liv;
}
}qy[maxq];
int d[maxn][maxn], lis[maxn], ans[maxq];
bool cmp(const int& x, const int& y) { return v[x]<v[y]; }
/*================================================================*/
struct Node{
int id, dis;
Node(int a=0, int b=0) :id(a), dis(b){}
bool operator < (const Node& x) const {
return dis > x.dis;
}
};
priority_queue<Node> q;
int dis[maxn];
int Dijkstra() {
while(!q.empty()) q.pop();
memset(dis, 0x3f, sizeof dis);
q.push(Node(s, 0));
dis[s] = 0;
int ans = 0;
while(!q.empty()) {
Node k = q.top(); q.pop();
int x = k.id;
if(k.dis != dis[x]) continue;
++ans;
if(x!=s && v[x] > liv) continue;
for(int i=head[x]; i; i=e[i].next) {
int to = e[i].to;
if(dis[to] > dis[x]+e[i].dis) {
dis[to] = dis[x]+e[i].dis;
if(dis[to] <= lid)
q.push(Node(to, dis[to]));
}
}
}
return ans-1;
}
int main(){
freopen("snackstore.in","r",stdin);
freopen("snackstore.out","w",stdout);
memset(d, 0x3f, sizeof d);
N = read(), M = read(), Q = read();
for(int i=1; i<=N; ++i) v[i] = read(), d[i][i] = 0;
for(int i=1,a,b,c; i<=M; ++i) {
a = read(), b = read(), c = read();
Add(a, b, c); Add(b, a, c);
if(d[a][b] > c) d[a][b] = d[b][a] = c;
d[a][b] = min(d[a][b], c);
}
if(Q<=10005) {
for(int i=1; i<=Q; ++i) {
s = read(), liv = read(), lid = read();
printf("%d\n", Dijkstra());
}
} else {
for(int i=1; i<=Q; ++i) {
qy[i].s = read();
qy[i].liv = read();
qy[i].lid = read();
qy[i].id = i;
}
for(int i=1; i<=N; ++i) lis[i] = i;
sort(qy+1, qy+Q+1);
sort(lis+1, lis+N+1, cmp);
int cur=1, p;
for(int i=1; i<=Q; ++i) {
while(cur<=N && v[lis[cur]]<=qy[i].liv) {
p = lis[cur];
for(int j=1; j<=N; ++j){
for(int k=1; k<=N; ++k){
if(j!=k && d[j][k]>d[j][p]+d[p][k]) {
d[j][k] = d[j][p]+d[p][k];
}
}
}
++cur;
}
for(int j=1; j<=N; ++j)
if(qy[i].s!=j && d[qy[i].s][j]<=qy[i].lid)
++ans[qy[i].id];
}
for(int i=1; i<=Q; ++i) printf("%d\n", ans[i]);
}
getchar(), getchar();
fclose(stdin); fclose(stdout);
return 0;
}