Submission #230384

#TimeUsernameProblemLanguageResultExecution timeMemory
230384arnold518Cities (BOI16_cities)C++14
100 / 100
3106 ms51368 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; const ll INF = 1e18; int N, M, K; int A[10]; vector<pii> adj[MAXN+10]; ll dist[MAXN+10][40]; struct Queue { int v; ll w; bool operator < (const Queue &p) const { return w>p.w; } }; int main() { int i, j, k; scanf("%d%d%d", &N, &K, &M); for(i=0; i<K; i++) scanf("%d", &A[i]); for(i=1; i<=M; i++) { int u, v, w; scanf("%d%d%d", &u, &v, &w); adj[u].push_back({v, w}); adj[v].push_back({u, w}); } for(i=1; i<=N; i++) for(j=1; j<(1<<K); j++) dist[i][j]=INF; for(i=0; i<K; i++) dist[A[i]][(1<<i)]=0; for(i=1; i<(1<<K); i++) { for(k=1; k<=N; k++) { for(j=i&(i-1); j; j=i&(j-1)) { dist[k][i]=min(dist[k][j]+dist[k][i^j], dist[k][i]); } } priority_queue<Queue> PQ; for(k=1; k<=N; k++) PQ.push({k, dist[k][i]}); while(!PQ.empty()) { Queue now=PQ.top(); PQ.pop(); if(now.w>dist[now.v][i]) continue; for(auto &nxt : adj[now.v]) { if(dist[nxt.first][i]>now.w+nxt.second) { dist[nxt.first][i]=now.w+nxt.second; PQ.push({nxt.first, dist[nxt.first][i]}); } } } } ll ans=INF; for(i=1; i<=N; i++) ans=min(ans, dist[i][(1<<K)-1]); printf("%lld\n", ans); }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &K, &M);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
cities.cpp:28:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(i=0; i<K; i++) scanf("%d", &A[i]);
                     ~~~~~^~~~~~~~~~~~~
cities.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &u, &v, &w);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...