답안 #128302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128302 2019-07-10T16:21:16 Z IOrtroiii Cities (BOI16_cities) C++14
100 / 100
3084 ms 46860 KB
#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

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);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 4984 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 7 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 857 ms 27876 KB Output is correct
2 Correct 803 ms 27708 KB Output is correct
3 Correct 553 ms 19536 KB Output is correct
4 Correct 107 ms 13240 KB Output is correct
5 Correct 516 ms 24436 KB Output is correct
6 Correct 103 ms 13148 KB Output is correct
7 Correct 11 ms 5240 KB Output is correct
8 Correct 9 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5368 KB Output is correct
2 Correct 13 ms 5368 KB Output is correct
3 Correct 11 ms 5240 KB Output is correct
4 Correct 11 ms 5368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1568 ms 34240 KB Output is correct
2 Correct 1585 ms 33964 KB Output is correct
3 Correct 1079 ms 26072 KB Output is correct
4 Correct 846 ms 24656 KB Output is correct
5 Correct 255 ms 16568 KB Output is correct
6 Correct 111 ms 15040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3022 ms 46860 KB Output is correct
2 Correct 2982 ms 46672 KB Output is correct
3 Correct 3084 ms 46652 KB Output is correct
4 Correct 2209 ms 38632 KB Output is correct
5 Correct 1825 ms 31008 KB Output is correct
6 Correct 386 ms 17872 KB Output is correct
7 Correct 127 ms 15140 KB Output is correct