Submission #968820

# Submission time Handle Problem Language Result Execution time Memory
968820 2024-04-24T06:52:45 Z blackslex Cities (BOI16_cities) C++17
0 / 100
859 ms 262144 KB
#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);
    vector<vector<ll>> d(n + 5, vector<ll>(n + 5, 1e18));
    for (int i = 1; i <= n; i++) d[i][i] = 0;
    while (m--) scanf("%d %d %lld", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z), d[x][y] = d[y][x] = z;
    for (int l = 1; l <= n; l++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    ll ans = 1e18;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int msk = 0; msk < (1 << k); msk++) {
                ll cur = d[i][j];
                for (int t = 0; t < k; t++) {
                    if (msk & (1 << t)) cur += d[i][c[t]];
                    else cur += d[j][c[t]];
                }
                ans = min(ans, cur);
            }
        }
    }
    printf("%lld", ans);
}

Compilation message

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:17:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     while (m--) scanf("%d %d %lld", &x, &y, &z), v[x].emplace_back(y, z), v[y].emplace_back(x, z), d[x][y] = d[y][x] = z;
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 127 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 859 ms 8480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 90 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 96 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -