#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define FI first
#define SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int prime = 999983;
const int INF = 0x7FFFFFFF;
const LL INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
vector<P> G[maxn];
int n, m, q;
struct Val {
LL prev, nowv;
int from, th, to;
};
bool operator <(const Val &a, const Val &b) {
return a.nowv < b.nowv;
}
bool operator > (const Val &a, const Val &b) {
return a.nowv > b.nowv;
}
struct Query {
int id, k;
} que[maxn];
LL ans[maxn];
bool operator <(const Query &a, const Query &b) {
return a.k < b.k;
}
int main(void)
{
int T; cin >> T;
while (T--) {
// int n;scanf("%d",&n);
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; ++i) G[i].clear();
for (int i = 1; i <= m; ++i) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
G[u].Pb(P(w, v));
}
for (int i = 1; i <= n; ++i) {
sort(G[i].begin(), G[i].end());
}
priority_queue<Val, vector<Val>, greater<Val>> Q;
for (int i = 1; i <= n; ++i) {
if (!G[i].empty())
Q.push(Val{0, G[i][0].first, i, 0, G[i][0].second});
}
for (int i = 1; i <= q; ++i) {
scanf("%d", &que[i].k);
que[i].id = i;
}
sort(que + 1, que + q + 1);
int j = 1;
int cnt = 0;
while (j <= q && !Q.empty()) {
Val tmp = Q.top(); Q.pop();
// cout << tmp.nowv << endl;
cnt++;
while (j <= q && que[j].k == cnt)
ans[que[j].id] = tmp.nowv, ++j;
if (tmp.th + 1 < G[tmp.from].size()) {
Q.push(Val{tmp.prev, tmp.prev + G[tmp.from][tmp.th + 1].first, tmp.from, tmp.th + 1, G[tmp.from][tmp.th + 1].second});
}
if (!G[tmp.to].empty()) {
Q.push(Val{tmp.nowv, tmp.nowv + G[tmp.to][0].first, tmp.to, 0, G[tmp.to][0].second});
}
}
for (int i = 1; i <= q; ++i)
printf("%lld\n", ans[i]);
}
return 0;
}
2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 1004 path
最新推荐文章于 2021-11-18 23:09:20 发布