Submission #1118367

#TimeUsernameProblemLanguageResultExecution timeMemory
1118367VinhLuuCities (BOI16_cities)C++17
100 / 100
2847 ms96640 KiB
#include <bits/stdc++.h> //#define int long long #define ll long long #define fi first #define se second #define pb push_back #define all(lmao) lmao.begin(), lmao.end() using namespace std; typedef pair<ll, ll> pii; const int N = 1e6 + 5; const int M = 1e6 + 5; const ll oo = 1e16; int n, k, m; ll f[N][(1 << 6)]; int a[N], rev[N]; vector<pii> p[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "v" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n >> k >> m; for(int i = 1; i <= k; i ++){ cin >> a[i]; rev[a[i]] = i; } for(int i = 1; i <= m; i ++) { int x, y, c; cin >> x >> y >> c; p[x].push_back({y, c}); p[y].push_back({x, c}); } for(int msk = 0; msk < (1 << k); msk ++) for(int i = 1; i <= n; ++ i) f[i][msk] = oo; for(int i = 1; i <= k; i ++) f[a[i]][(1 << (i - 1))] = 0; for(int msk = 1; msk < (1 << k); msk ++){ priority_queue<pii, vector<pii>, greater<pii>> pq; for(int i = 1; i <= n; i ++){ for(int sub = msk; sub > 0; sub = (sub - 1) & msk){ f[i][msk] = min(f[i][msk], f[i][sub] + f[i][(msk ^ sub)]); } pq.push({f[i][msk], i}); } while(!pq.empty()){ ll w, u; tie(w, u) = pq.top(); pq.pop(); if(w > f[u][msk]) continue; for(auto [j, val] : p[u]) if(f[j][msk] > w + val){ pq.push({f[j][msk] = w + val, j}); } } } ll ans = oo; for(int i = 1; i <= n; i ++) ans = min(ans, f[i][(1 << k) - 1]); cout << ans; }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen(task ".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...