Submission #969402

#TimeUsernameProblemLanguageResultExecution timeMemory
969402blackslexCities (BOI16_cities)C++17
0 / 100
713 ms35692 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<ll, ll>; int n, m, k, x, y, 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 %d", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z); vector<vector<int>> dp((1 << k) + 5, vector<int>(n + 5, 1e9)); 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<int> &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("%d", *min_element(dp[(1 << k) - 1].begin(), dp[(1 << k) - 1].end())); }

Compilation message (stderr)

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