Submission #128302

#TimeUsernameProblemLanguageResultExecution timeMemory
128302IOrtroiiiCities (BOI16_cities)C++14
100 / 100
3084 ms46860 KiB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
const ll inf = 1e18;
const int N = 200200;

ll d[1 << 5][N];
vector<pair<int, int>> g[N];

int main() {
   int n, k, m;
   scanf("%d %d %d", &n, &k, &m);
   for (int i = 1; i < (1 << k); ++i) {
      for (int j = 1; j <= n; ++j) {
         d[i][j] = inf;
      }
   }
   for (int i = 0; i < k; ++i) {
      int v;
      scanf("%d", &v);
      d[1 << i][v] = 0;
   }
   for (int i = 1; i <= m; ++i) {
      int u, v, w;
      scanf("%d %d %d", &u, &v, &w);
      g[u].emplace_back(v, w);
      g[v].emplace_back(u, w);
   }
   for (int i = 1; i < (1 << k); ++i) {
      for (int j = i; ; j = (j - 1) & i) {
         for (int u = 1; u <= n; ++u) {
            d[i][u] = min(d[i][u], d[j][u] + d[i ^ j][u]);
         }
         if (j == 0) {
            break;
         }
      }
      priority_queue<pair<ll, int>> q;
      for (int u = 1; u <= n; ++u) {
         q.emplace(-d[i][u], u);
      }
      while (!q.empty()) {
         ll du = -q.top().first;
         int u = q.top().second;
         q.pop();
         if (du != d[i][u]) {
            continue;
         }
         for (auto e : g[u]) {
            int v, w;
            tie(v, w) = e;
            if (d[i][v] > d[i][u] + w) {
               d[i][v] = d[i][u] + w;
               q.emplace(-d[i][v], v);
            }
         }
      }
   }
   printf("%lld\n", *min_element(d[(1 << k) - 1] + 1, d[(1 << k) - 1] + n));
}

Compilation message (stderr)

cities.cpp: In function 'int main()':
cities.cpp:14:9: 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:22:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &v);
       ~~~~~^~~~~~~~~~
cities.cpp:27:12: 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...