Submission #1281459

#TimeUsernameProblemLanguageResultExecution timeMemory
1281459cheskaVoting Cities (NOI22_votingcity)C++20
25 / 100
1095 ms4852 KiB
//dominater orz //evenvalue orz //roumak orz //melody orz //cpp orz #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define ppii pair<pii, pii> #define tiii tuple<int, int, int> #define g0 get<0> #define g1 get<1> #define g2 get<2> #define f first #define s second #define pb push_back const int N = 2e5+5; const int MOD = 1e9+7; struct state { int d, m, u; }; struct comp { bool operator()(const state &a, const state &b) const { return a.d > b.d; } }; signed main() { // freopen("in.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> t; for (int i = 0; i < k; i++) { int j; cin >> j; t.pb(j); } vector<vector<pii>> a(n); while (m--) { int u, v, w; cin >> u >> v >> w; a[u].pb({v, w}); } int q; cin >> q; while (q--) { int s; cin >> s; vector<int> p(5); for (int i = 0; i < 5; i++) cin >> p[i]; vector<vector<int>> ans(32, vector<int>(n, LLONG_MAX)); priority_queue<state, vector<state>, comp> pq; ans[0][s] = 0; pq.push({0, 0, s}); while (!pq.empty()) { auto [d, m, u] = pq.top(); pq.pop(); if (d > ans[m][u]) continue; for (pii v : a[u]) { if (ans[m][v.f] > d+v.s) { ans[m][v.f] = d+v.s; pq.push({ans[m][v.f], m, v.f}); } } for (int i = 0; i < 5; i++) { if (!((1<<i)&m)) { for (pii v : a[u]) { int nd = v.s*(10-i-1)/10; if (ans[m+(1<<i)][v.f] > d+nd) { ans[m+(1<<i)][v.f] = d+nd; pq.push({ans[m+(1<<i)][v.f], m+(1<<i), v.f}); } } } } } int ans2 = LLONG_MAX; for (int i = 0; i < 32; i++) { bool ch = true; int x = 0; for (int j = 0; j < 5; j++) { if (i&(1<<j)) { if (p[j] != -1) x += p[j]; else {ch = false; break;} } } if (!ch) continue; for (int j : t) { if (ans[i][j] == LLONG_MAX) continue; ans2 = min(ans2, ans[i][j]+x); } } if (ans2 != LLONG_MAX) cout << ans2 << '\n'; else cout << "-1\n"; } }
#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...