답안 #968814

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968814 2024-04-24T06:35:41 Z blackslex Cities (BOI16_cities) C++17
22 / 100
116 ms 3552 KB
#include<bits/stdc++.h>

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

int n, m, k;

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 = 1e18;
    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:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d %d", &n, &k, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cities.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for (auto &e: c) scanf("%d", &e), e--;
      |                      ~~~~~^~~~~~~~~~
cities.cpp:14:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for (auto &[z, x, y]: v) scanf("%d %d %lld", &x, &y, &z), x--, y--;
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 116 ms 404 KB Output is correct
3 Correct 74 ms 344 KB Output is correct
4 Correct 56 ms 408 KB Output is correct
5 Correct 27 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 3552 KB Output isn't correct
2 Halted 0 ms 0 KB -