Submission #968809

# Submission time Handle Problem Language Result Execution time Memory
968809 2024-04-24T06:33:43 Z blackslex Cities (BOI16_cities) C++17
0 / 100
114 ms 3556 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using tp = tuple<ll, int, int>;

int n, m, k, x, y;
ll z;

int main() {
    scanf("%d %d %d", &n, &k, &m);
    vector<int> c(k);
    vector<tp> v(m);
    for (auto &e: c) scanf("%d", &e), e--;
    for (auto &[z, x, y]: v) scanf("%d %d %lld", &x, &y, &z), x--, y--;
    sort(v.begin(), v.end());
    ll ans = 1e9;
    auto get = [&] (int msk) {
        for (auto &e: c) if (!(msk & (1 << e))) return;
        vector<int> par(n); iota(par.begin(), par.end(), 0);
        function<int(int)> fset = [&] (int a) {return (par[a] == a ? a : par[a] = fset(par[a]));};
        ll cur = 0;
        for (auto &[z, x, y]: v) {
            if (!(msk & (1 << x)) || !(msk & (1 << y))) continue;
            if (fset(x) != fset(y)) par[fset(x)] = fset(y), cur += z;
        }
        for (auto &e: c) for (auto &E: c) if (fset(e) != fset(E)) return;
        ans = min(ans, cur);
    };
    for (int i = 0; i < (1 << n); i++) get(i);
    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), e--;
      |                      ~~~~~^~~~~~~~~~
cities.cpp:15:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     for (auto &[z, x, y]: v) scanf("%d %d %lld", &x, &y, &z), x--, y--;
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 114 ms 408 KB Output is correct
3 Incorrect 68 ms 416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 3556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -