Submission #930930

#TimeUsernameProblemLanguageResultExecution timeMemory
930930AndiRVoting Cities (NOI22_votingcity)C++14
45 / 100
1064 ms4048 KiB
// Author: Tanasescu Andrei-Rares
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>
#include <cassert>
 
#define fi first
#define se second
#define pb push_back
#define pf push_front
 
using namespace std;
 
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll Nmax=5e3, inf=(ll)1e18;
 
int n, m, k, q, st, p[5];
bool fn[Nmax];
ll dist[32][Nmax];
vector<pii> ad[Nmax];
struct info{
    int nod, tip;
    ll cost;
    bool operator<(const info &nxt)const{
        return cost>nxt.cost;
    }
};
priority_queue<info> pq;
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    cin>>n>>m>>k;
    int nr;
    for (int i=0; i<k; i++){
        cin>>nr;
        fn[nr]=1;
    }
    int a, b, c;
    for (int i=0; i<m; i++){
        cin>>a>>b>>c;
        ad[a].pb({b, c});
    }
    cin>>q;
    while (q--){
        cin>>st;
        for (int i=0; i<5; i++)
            cin>>p[i];
        for (int i=0; i<n; i++)
            for (int j=0; j<32; j++)
                dist[j][i]=inf;
        dist[0][st]=0;
        pq.push({st, 0, 0});
        while (!pq.empty() && !fn[pq.top().nod]){
            info crt=pq.top();
            pq.pop();
            for (auto it:ad[crt.nod]){
                if (dist[crt.tip][it.fi]>crt.cost+it.se){
                    dist[crt.tip][it.fi]=crt.cost+it.se;
                    pq.push({it.fi, crt.tip, crt.cost+it.se});
                }
                for (int t=0; t<5; t++){
                    int newtip=(crt.tip | (1<<t));
                    ll newcost=crt.cost+it.se-(ll)it.se*(t+1)/10+p[t];
                    if (p[t]!=-1 && newtip!=crt.tip && dist[newtip][it.fi]>newcost){
                        dist[newtip][it.fi]=newcost;
                        pq.push({it.fi, newtip, newcost});
                    }
                }
            }
        }
        if (pq.empty())
            cout<<"-1\n";
        else{
            cout<<pq.top().cost<<'\n';
            while (!pq.empty())
                pq.pop();
        }
    }
 
    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...