Submission #554556

# Submission time Handle Problem Language Result Execution time Memory
554556 2022-04-28T18:14:46 Z Soumya1 Cities (BOI16_cities) C++17
36 / 100
2812 ms 44824 KB
#include <bits/stdc++.h>
#ifdef __LOCAL__
#include <debug_local.h>
#endif
using namespace std;
const int mxN = 1e5 + 5;
const long long inf = 1e18;
using ll = long long;
int idx[mxN];
vector<pair<int, int>> ad[mxN];
vector<int> terminals;
ll d[mxN][32];
void testCase() {
  int n, k, m;
  cin >> n >> k >> m;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    terminals.push_back(x);
    idx[x] = i;
  }
  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    ad[u].push_back({v, w});
    ad[v].push_back({u, w});
  }
  for (int i = 1; i <= n; i++) {
    for (int mask = 0; mask < (1 << k); mask++) d[i][mask] = inf;
  }
  for (int t : terminals) d[t][1 << idx[t]] = 0;
  for (int mask = 1; mask < (1 << k); mask++) {
    for (int i = 1; i <= n; i++) {
      for (int s_mask = mask & (mask - 1); s_mask > 0; s_mask = s_mask & (s_mask - 1)) {
        d[i][mask] = min(d[i][mask], d[i][s_mask] + d[i][mask ^ s_mask]);
      }
    }
    priority_queue<pair<ll, int>> pq;
    for (int i = 1; i <= n; i++) pq.push({-d[i][mask], i});
    while (!pq.empty()) {
      auto [_, u] = pq.top();
      pq.pop();
      if (d[u][mask] != -_) continue;
      for (auto [v, w] : ad[u]) {
        if (d[v][mask] > d[u][mask] + w) {
          d[v][mask] = d[u][mask] + w;
          pq.push({-d[v][mask], v});
        }
      }
    }
  }
  ll ans = inf;
  for (int i = 1; i <= n; i++) ans = min(ans, d[i][(1 << k) - 1]);
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2672 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 759 ms 40872 KB Output is correct
2 Correct 704 ms 44728 KB Output is correct
3 Correct 486 ms 36632 KB Output is correct
4 Correct 59 ms 11052 KB Output is correct
5 Correct 355 ms 44624 KB Output is correct
6 Correct 66 ms 11000 KB Output is correct
7 Correct 6 ms 3080 KB Output is correct
8 Correct 4 ms 3076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3028 KB Output is correct
2 Incorrect 7 ms 3104 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1416 ms 40892 KB Output is correct
2 Correct 1412 ms 44780 KB Output is correct
3 Incorrect 929 ms 36652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2812 ms 40740 KB Output is correct
2 Incorrect 2742 ms 44824 KB Output isn't correct
3 Halted 0 ms 0 KB -