Submission #1272368

#TimeUsernameProblemLanguageResultExecution timeMemory
1272368neisennVoting Cities (NOI22_votingcity)C++20
100 / 100
65 ms6484 KiB
#pragma GCC("avx2")
#pragma GCC("unroll-loops","Ofast")
#pragma GCC("O3")

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef tuple<ll, int, int> tii;
const char nl = '\n';
const int mod = 1e9+7;
const ll inf = 1e18;

void solve(){
    int n, m, k; cin >> n >> m >> k;
    vector<int> t;
    for (int i = 0; i < k; i++){
        int x; cin >> x;
        t.pb(x);
    }
    vector<vector<pil>> adj(n+1);
    for (int i = 0; i < m; i++){
        int u, v; cin >> u >> v;
        ll w; cin >> w;
        adj[v].pb({u, w}); 
    }
    int q; cin >> q;
    if (k == 0){
        while (q--){
            int st; ll p1, p2, p3, p4, p5;
            cin >> st >> p1 >> p2 >> p3 >> p4 >> p5;
            cout << "-1\n";
        }
        return;
    }
    priority_queue<tii, vector<tii>, greater<tii>> pq;
    vector<vector<ll>> dis(n+1, vector<ll> (32, inf));
    for (int cur : t){
        dis[cur][0] = 0;
        pq.push({0, cur, 0});
    }
    while (pq.size()){
        auto [cost, cur, mask] = pq.top();
        pq.pop();
        // cout << cost << ' ' << cur << ' ' << mask << nl;
        if (dis[cur][mask] < cost) continue;
        for (auto [ch, w] : adj[cur]){
            ll nc = cost+w;
            if (dis[ch][mask] > nc){
                dis[ch][mask] = nc;
                pq.push({nc, ch, mask});
            }
            for (int j = 0; j < 5; j++){
                if (!((1 << j) & mask)){
                    int bit = mask|(1 << j);
                    ll nw = w-(w*((j+1)*10)/100);
                    nc = cost+nw;
                    // cout << nc << ' ' << ch << ' ' << bit << nl;
                    if (dis[ch][bit] > nc){
                        dis[ch][bit] = nc;
                        pq.push({nc, ch, bit});
                    }
                }
            }
        }
    }
    while (q--){
        int st; ll p[5];
        cin >> st >> p[0] >> p[1] >> p[2] >> p[3] >> p[4];
        ll ans = inf;
        for (int i = 0; i < 32; i++){
            ll ret = 0;
            bool ok = 1;
            for (int j = 0; j < 5; j++){
                if ((1 << j) & i){
                    if (p[j] == -1){
                        ok = 0; 
                        break;
                    } else ret += p[j];
                }
            }
            if (ok){
                ans = min(ans, dis[st][i]+ret);
            }
        } 
        cout << (ans == inf ? -1 : ans) << nl;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1; // cin >> t;
    while (t--){
        solve();
    }
    return 0;
} 
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...