Submission #1075439

#TimeUsernameProblemLanguageResultExecution timeMemory
1075439vjudge1Cities (BOI16_cities)C++17
100 / 100
2016 ms46656 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define fi first #define se second #define all(x) x.begin(), x.end() mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 1e5 + 5; const int inf = 1e18 + 5; vector<pair<int, int>> g[NM]; int n, k, m, dp[NM][32], imp[5]; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq; void solve() { cin >> n >> k >> m; for (int i = 0; i < k; i++) cin >> imp[i]; while (m--) { int u, v, w; cin >> u >> v >> w; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } for (int msk = 1; msk < (1 << k); msk++) { for (int i = 1; i <= n; i++) dp[i][msk] = inf; if (__builtin_popcount(msk) == 1) dp[imp[__lg(msk)]][msk] = 0; for (int u = 1; u <= n; u++) for (int smsk = (msk - 1) & msk; smsk; smsk = (smsk - 1) & msk) setmin(dp[u][msk], dp[u][smsk] + dp[u][msk ^ smsk]); for (int u = 1; u <= n; u++) pq.push({dp[u][msk], u}); while (!pq.empty()) { auto t = pq.top(); pq.pop(); if (dp[t.se][msk] != t.fi) continue; for (auto v : g[t.se]) if (dp[v.fi][msk] > t.fi + v.se) { dp[v.fi][msk] = t.fi + v.se; pq.push({dp[v.fi][msk], v.fi}); } } } int res = inf; for (int i = 1; i <= n; i++) setmin(res, dp[i][(1 << k) - 1]); cout << res; } signed main() { fastIO if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int tc = 1; // cin >> tc; // pre(); while (tc--) solve(); }

Compilation message (stderr)

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