Submission #1059438

#TimeUsernameProblemLanguageResultExecution timeMemory
1059438vjudge1Cities (BOI16_cities)C++17
74 / 100
6033 ms196952 KiB
#include<bits/stdc++.h> #define fori(i,a,b) for(int i=a;i<=b;i++) #define ii pair<int,long long > #define fi first #define se second #define pb push_back using namespace std; const int M=1e5+10; int n,m,k; long long f[M][1<<6]; vector<ii> ke[M]; struct node { int u,mask; long long val; }; struct cmp { bool operator() (node a,node b) { return a.val>b.val; } }; priority_queue<node,vector<node> ,cmp> h; long long tmp[1<<6]; void dij() { while(!h.empty()) { node u=h.top();h.pop(); if(f[u.u][u.mask]<u.val) continue; for(ii v:ke[u.u]) { fori(i,0,(1<<k)-1) tmp[i|u.mask]=min(tmp[i|u.mask],u.val+f[v.fi][i]+v.se); fori(i,0,(1<<k)-1) { if(tmp[i]<f[v.fi][i]) { f[v.fi][i]=tmp[i]; h.push({v.fi,i,f[v.fi][i]}); } 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; fori(i,1,n) { fori(j,1,(1<<k)-1) f[i][j]=1e18; } fori(i,1,(1<<k)-1) tmp[i]=1e18; fori(i,0,k-1) { int x; cin >> x; h.push({x,1<<i,0}); f[x][1<<i]=0; } fori(i,1,m) { long long u,v,w; cin >> u >> v >> w; ke[u].pb({v,w}); ke[v].pb({u,w}); } dij(); long long kq=1e18; fori(i,1,n) kq=min(kq,f[i][(1<<k)-1]); cout << kq; }

Compilation message (stderr)

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