比赛 |
NOIP模拟赛by mzx Day1 |
评测结果 |
AWAAWWWWWW |
题目名称 |
零食店 |
最终得分 |
30 |
用户昵称 |
KZNS |
运行时间 |
2.140 s |
代码语言 |
C++ |
内存使用 |
4.75 MiB |
提交时间 |
2016-10-19 21:43:14 |
显示代码纯文本
//KZNS
#include <cstdio>
#include <algorithm>
using namespace std;
#define Nmax 105
#define INF 100000005
int input() {
int a = 0;
char c = getchar();
while (!('0' <= c && c <= '9'))
c = getchar();
while ('0' <= c && c <= '9') {
a = a * 10 + c - '0';
c = getchar();
}
return a;
}
int N, M, Q;
int V[Nmax];
int gp[Nmax][Nmax][Nmax];
int vls[Nmax];
int als[Nmax][Nmax] = {0};
inline bool cmp2(const int a, const int b) {
return V[a] < V[b];
}
void init() {
N = input();
M = input();
Q = input();
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
gp[0][i][j] = INF;
for (int i = 1; i <= N; i++) {
V[i] = input();
vls[i] = i;
gp[0][i][i] = 0;
}
int a, b, c;
for (int i = 0; i < M; i++) {
a = input();
b = input();
c = input();
gp[0][a][b] = min(gp[0][a][b], c);
gp[0][b][a] = min(gp[0][b][a], c);
}
sort(vls+1, vls+1+N, cmp2);
int k;
for (int u = 1; u <= N; u++)
for (int i = 1; i <= N; i++)
for (int j = 1; j <= N; j++)
gp[u][i][j] = min(gp[u-1][i][j], gp[u-1][i][vls[u]] + gp[u-1][vls[u]][j]);
for (int u = 0; u <= N; u++)
for (int i = 1; i <= N; i++)
sort(gp[u][i]+1, gp[u][i]+1+N);
}
void work() {
int f, c, d;
int l, r, md;
int ll, rr;
for (int i = 0; i < Q; i++) {
f = input();
c = input();
d = input();
l = 0;
r = N;
while (r-l > 1) {
md = l+r>>1;
if (vls[md] <= c)
l = md;
else
r = md;
}
if (vls[r] <= c)
l = r;
ll = 1;
rr = N;
while (rr - ll > 1) {
md = ll+rr>>1;
if (gp[l][f][md] <= d)
ll = md;
else
rr = md;
}
if (gp[l][f][rr] <= d)
ll = rr;
printf("%d\n", ll - 1);
}
}
int main() {
freopen("snackstore.in", "r", stdin);
freopen("snackstore.out", "w", stdout);
init();
work();
return 0;
}
//UBWH