# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
848326 | KN200711 | Voting Cities (NOI22_votingcity) | C++14 | 171 ms | 10696 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
# include <bits/stdc++.h>
# define ll long long
# define fi first
# define se second
using namespace std;
int N, E, K;
vector<int> T;
vector< pair<int, ll> > edge[5001];
ll dp[32][5001];
bool vis[32][5001];
int main() {
scanf("%d %d %d", &N, &E, &K);
T.resize(K);
for(int i=0;i<K;i++) {
scanf("%d", &T[i]);
}
for(int i=0;i<E;i++) {
int a, b;
ll c;
scanf("%d %d %lld", &a, &b, &c);
edge[b].push_back(make_pair(a, c));
}
for(int i=0;i<32;i++) {
for(int k=0;k<N;k++) dp[i][k] = -1;
}
priority_queue< pair<int, pair<ll, int> > > PQ;
for(int i=0;i<K;i++) {
PQ.push(make_pair(0, make_pair(0, T[i])));
}
while(!PQ.empty()) {
int a, c;
ll b;
a = -PQ.top().fi;
b = -PQ.top().se.fi;
c = PQ.top().se.se;
PQ.pop();
if(dp[a][c] != -1) continue;
// cout<<"a : "<<a<<" "<<c<<endl;
dp[a][c] = b;
for(auto p : edge[c]) {
for(int k=0;k<5;k++) {
if(!(a&(1 << k))) {
if(dp[a^(1 << k)][c] == -1) PQ.push(make_pair(-(a ^ (1 << k)), make_pair(-b - (10 - k - 1) * p.se / 10, p.fi)));
}
}
if(dp[a][p.fi] == -1) {
PQ.push(make_pair(-a, make_pair(-b-p.se, p.fi)));
}
}
}
int Q;
scanf("%d", &Q);
while(Q--) {
int S;
ll P[5];
scanf("%d", &S);
for(int i=0;i<5;i++) scanf("%lld", &P[i]);
ll as = 0ll, ans = 1e18;
for(int i=0;i<32;i++) {
// cout<<"i : "<<i<<" "<<dp[i][S]<<endl;
if(dp[i][S] == -1) continue;
as = dp[i][S];
for(int k=0;k<5;k++) {
if(i&(1 << k)) {
if(P[k] == -1) {
as = 1e18;
break;
}
else as += P[k];
}
}
ans = min(ans, as);
}
if(ans >= 1e18) ans = -1;
printf("%lld\n", ans);
}
return 0;
}
Compilation message (stderr)
# | 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... |