답안 #968807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968807 2024-04-24T06:31:00 Z blackslex Cities (BOI16_cities) C++17
0 / 100
120 ms 3552 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;
    for (int i = 0; i < (1 << n); i++) {
        bool ck = 1;
        for (auto &e: c) ck &= !!(i & (1 << e));
        if (!ck) continue;
        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 (!(i & (1 << x)) || !(i & (1 << y))) continue;
            if (fset(x) != fset(y)) par[fset(x)] = fset(y), cur += z;
        }
        bool ck2 = 1;
        for (auto &e: c) for (auto &E: c) ck2 &= (fset(e) == fset(E));
        if (ck2) 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), 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--;
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 120 ms 348 KB Output is correct
3 Incorrect 73 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 3552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 65 ms 3416 KB Output isn't correct
2 Halted 0 ms 0 KB -