比赛 |
NOIP模拟赛by mzx Day1 |
评测结果 |
WAWWWWWTTT |
题目名称 |
零食店 |
最终得分 |
10 |
用户昵称 |
Tiny |
运行时间 |
3.492 s |
代码语言 |
C++ |
内存使用 |
90.48 MiB |
提交时间 |
2016-10-19 21:29:39 |
显示代码纯文本
#include <stdio.h>
#include <string.h>
#include <queue>
const int MAX_BUF = 100 * 1024 * 1024;
int buf_cnt = 0;
char read_buf[MAX_BUF];
template <typename T> inline void Read_buf(T &num) {
num = 0; bool minus = false;
while (read_buf[buf_cnt] < '-' || read_buf[buf_cnt] > '9') ++buf_cnt;
if (read_buf[buf_cnt] == '-') { minus = true; ++buf_cnt; }
while (read_buf[buf_cnt] >= '0' && read_buf[buf_cnt] <= '9')
num = num * 10 + read_buf[buf_cnt++] - '0';
if (minus) num = -num;
}
template <typename T> inline void Read(T &num) {
num = 0; char ch; bool minus = false;
while (ch = getchar(), ch < '-' || ch > '9');
if (ch == '-') { minus = true; ch = getchar(); }
while (num = num * 10 + ch - '0', ch = getchar(), ch >= '0' && ch <= '9');
if (minus) num = -num;
}
const size_t MAXN = 100 + 10, MAXM = 10000 + 10;
int n, m;
int cost[MAXN];
struct Edge { int v, w, ne; } E[MAXM << 1];
int head[MAXN], tot_e = 0;
int dis[MAXN];
struct Node {
int t, w;
inline bool operator <(const Node &b) const { return w > b.w; }
};
std::priority_queue<Node> Q;
inline void Insert(const int &u, const int &v, const int &w) {
E[++tot_e] = (Edge){v, w, head[u]}; head[u] = tot_e;
}
inline void Dijkstra(const int &s, const int &mc) {
memset(dis, 0x3f, sizeof(dis));
Q.push((Node){s, 0});
dis[s] = 0;
while (!Q.empty()) {
Node u = Q.top(); Q.pop();
if (dis[u.t] != u.w) continue;
for (int i = head[u.t], v; i; i = E[i].ne) {
v = E[i].v;
if (dis[v] > u.w + E[i].w && cost[v] <= mc) {
dis[v] = u.w + E[i].w;
Q.push((Node){v, dis[v]});
}
}
}
}
int main() {
#define SUBMIT
#ifdef SUBMIT
freopen("snackstore.in", "r", stdin);
freopen("snackstore.out", "w", stdout);
fread(read_buf, 1, MAX_BUF, stdin);
#endif
int q; Read_buf(n); Read_buf(m); Read_buf(q);
for (int i = 1; i <= n; ++i) Read_buf(cost[i]);
int u, v, w;
for (int i = 1; i <= m; ++i) {
Read_buf(u); Read_buf(v); Read_buf(w);
Insert(u, v, w); Insert(v, u, w);
}
while (q--) {
Read_buf(u); Read_buf(v); Read_buf(w);
Dijkstra(u, v);
int ans = 1;
for (int i = 1; i <= n; ++i)
if (dis[i] <= w) ++ans;
printf("%d\n", ans);
}
#ifndef SUBMIT
puts("\n--------------------");
getchar(); getchar();
#else
fclose(stdin); fclose(stdout);
#endif
return 0;
}