Submission #969404

#TimeUsernameProblemLanguageResultExecution timeMemory
969404blackslexCities (BOI16_cities)C++17
100 / 100
2229 ms54912 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; int n, m, k, x, y; ll z; int main() { scanf("%d %d %d", &n, &k, &m); vector<int> c(k); vector<vector<pii>> v(n + 5, vector<pii>()); for (auto &e: c) scanf("%d", &e); while (m--) scanf("%d %d %lld", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z); vector<vector<ll>> dp((1 << k) + 5, vector<ll>(n + 5, 1e18)); for (int i = 0; i < k; i++) dp[1 << i][c[i]] = 0; for (int i = 1; i < (1 << k); i++) { for (int j = i; j; j = (j - 1) & i) { for (int r = 1; r <= n; r++) { dp[i][r] = min(dp[i][r], dp[j][r] + dp[i ^ j][r]); } } auto dijk = [&] (vector<ll> &curd) { priority_queue<pii, vector<pii>, greater<pii>> pq; for (int j = 1; j <= n; j++) pq.emplace(curd[j], j); while (!pq.empty()) { auto [nd, nn] = pq.top(); pq.pop(); for (auto &[tn, td]: v[nn]) if (curd[tn] > curd[nn] + td) pq.emplace(curd[tn] = curd[nn] + td, tn); } }; dijk(dp[i]); } printf("%lld", *min_element(dp[(1 << k) - 1].begin(), dp[(1 << k) - 1].end())); }

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %d %d", &n, &k, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:14:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for (auto &e: c) scanf("%d", &e);
      |                      ~~~~~^~~~~~~~~~
cities.cpp:15:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     while (m--) scanf("%d %d %lld", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...