Submission #1059757

#TimeUsernameProblemLanguageResultExecution timeMemory
1059757vjudge1Cities (BOI16_cities)C++17
100 / 100
5904 ms169788 KiB
#include<bits/stdc++.h> using namespace std; const int M=1e5+10; int n,m,k; long long f[M][1<<5]; vector<pair<int,int>> ke[M]; priority_queue<tuple<long long ,int ,int >,vector<tuple<long long ,int ,int > > ,greater<tuple<long long ,int ,int > > > h; long long tmp[1<<5]; vector<int> submask[1<<5]; void dij() { while(!h.empty()) { auto [val,mask,u]=h.top();h.pop(); if(f[u][mask]<val) continue; for(pair<int,int> v:ke[u]) { for(int i:submask[mask]) tmp[i]=min(f[v.first][i],val+f[v.first][i^mask]+v.second); for(int i:submask[mask]) { if(tmp[i]<f[v.first][i]) { f[v.first][i]=tmp[i]; h.push({f[v.first][i],i,v.first}); tmp[i]=1e18; } } } } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "1" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } cin >> n >> k >> m; for(int i=0;i<(1<<k);i++) { for(int j=0;j<(1<<k);j++) if((i&j)==i) submask[i].push_back(j); } for(int i=1;i<=n;i++) { for(int j=1;j<(1<<k);j++) f[i][j]=1e18; } for(int i=0;i<(1<<k);i++) tmp[i]=1e18; for(int i=0;i<k;i++) { int x; cin >> x; h.push({0,1<<i,x}); f[x][1<<i]=0; } for(int i=1;i<=m;i++) { int u,v; long long w; cin >> u >> v >> w; ke[u].push_back({v,w}); ke[v].push_back({u,w}); } dij(); long long kq=1e18; for(int i=1;i<=n;i++) kq=min(kq,f[i][(1<<k)-1]); cout << kq; }

Compilation message (stderr)

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