Submission #361276

#TimeUsernameProblemLanguageResultExecution timeMemory
361276Killer2501Cities (BOI16_cities)C++14
100 / 100
5325 ms139404 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "talltree" #define pll pair<ll, ll> #define pii pair<ll, pll> #define fi first #define se second #define ull unsigned long long using namespace std; const ll mod = 1e15+7; const ll N = 2e5+5; vector<pll> adj[N]; vector<ll> kq; ll n, m, t, k, b[N], p, lab[N], u, v, h[N], a[N], ans, tong, d[N][32]; priority_queue< pii, vector<pii>, greater<pii> > pq; void sol() { cin >> n >> k >> m; for(int i = 0; i < k; i ++)cin >> a[i]; for(int i = 1; i <= m; i ++) { ll x, y, w; cin >> x >> y >> w; adj[x].pb({w, y}); adj[y].pb({w, x}); } for(int i = 1; i <= n; i ++) { pii u; u.fi = 0; u.se.fi = i; u.se.se = 0; pq.push(u); for(int j = 1; j < (1<<k);j ++)d[i][j] = mod; } for(int i = 0; i < k; i ++) { d[a[i]][(1<<i)] = 0; pii u; u.fi = 0; u.se.fi = a[i]; u.se.se = (1<<i); pq.push(u); } while(!pq.empty()) { pii u = pq.top(); pq.pop(); if(d[u.se.fi][u.se.se] != u.fi)continue; if(u.se.se == (1<<k)-1) { cout << u.fi; return; } for(int j = 0; j < k; j ++) { t = u.se.se | (1<<j); if(d[u.se.fi][t] > u.fi + d[u.se.fi][(1<<j)]) { d[u.se.fi][t] = u.fi + d[u.se.fi][(1<<j)]; pii v; v.fi = d[u.se.fi][t]; v.se.fi = u.se.fi; v.se.se = t; pq.push(v); } } for(pll x : adj[u.se.fi]) { if(d[x.se][u.se.se] > u.fi + x.fi) { d[x.se][u.se.se] = u.fi + x.fi; pii v; v.fi = u.fi + x.fi; v.se.fi = x.se; v.se.se = u.se.se; pq.push(v); } } } } int main() { if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); }

Compilation message (stderr)

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