#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif
const int mn = 5e3 + 5, mod = 1e9 + 7, inf = 2e18;
int n, m, k, q, t[mn], d[mn][1 << 5];
vector <pii> a[mn];
void dijsktra(int s, vector <int>& p){
for(int i = 1; i <= n; i++){
for(int j = 0; j < 32; j++){
d[i][j] = inf;
}
}
priority_queue <array<int, 3>, vector<array<int, 3>>, greater<array<int, 3>> > pq;
for(int mask = 0; mask < 32; mask++){
bool ok = true;
d[s][mask] = 0;
for(int i = 0; i < 5; i++){
if(mask & (1 << i)){
d[s][mask] += p[i];
if(p[i] == -1) ok = false;
}
}
if(ok) pq.push({d[s][mask], s, mask});
else d[s][mask] = inf;
}
while(pq.size()){
auto [c, u, mask] = pq.top(); pq.pop();
debug(c, u, mask);
if(c > d[u][mask]) continue;
for(auto [v, w] : a[u]){
if(d[v][mask] > d[u][mask] + w){
d[v][mask] = d[u][mask] + w;
pq.push({d[v][mask], v, mask});
}
for(int i = 0; i < 5; i++){
if(mask & (1 << i) && p[i] != -1){
int new_mask = mask ^ (1 << i), new_w = w * (9 - i) / 10;
debug(v, new_mask, d[v][new_mask], u, mask, d[u][mask], i, new_w);
if(d[v][new_mask] > d[u][mask] + new_w){
d[v][new_mask] = d[u][mask] + new_w;
pq.push({d[v][new_mask], v, new_mask});
}
}
}
}
}
int res = 0;
for(int i = 1; i <= k; i++) res = max(res, d[t[i]][0]);
cout << res << '\n';
}
void solve() {
cin >> n >> m >> k;
for(int i = 1; i <= k; i++){
cin >> t[i];
t[i] ++;
}
for(int i = 1; i <= m; i++){
int u, v, w; cin >> u >> v >> w;
u ++, v ++;
a[u].push_back({v, w});
}
cin >> q;
while(q--){
int s; cin >> s;
s ++;
vector <int> p(5); for(int i = 0; i < 5; i++) cin >> p[i];
dijsktra(s, p);
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
#define task "Kawabata"
if (fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
// Don't wanna lose anymore T_T
// Never let me go - Kazuo Ishiguro
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(task".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | freopen(task".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |