답안 #764848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
764848 2023-06-24T05:41:05 Z The_Samurai Parkovi (COCI22_parkovi) C++17
10 / 110
90 ms 15300 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int n, k;
vector<bool> vis;
vector<vector<pair<int, int>>> g;

void solve() {
    cin >> n >> k;
    g.assign(n + 1, {});
    for (int i = 1; i < n; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
    }
    if (n <= 20) {
        ll ans = 1e18;
        vector<int> built;
        for (int i = 0; i < (1 << n); i++) {
            if (__builtin_popcount(i) != k) {
                continue;
            }
            priority_queue<pair<ll, int>> pq;
            vector<int> now;
            for (int j = 0; j < n; j++) {
                if ((1 << j) & i) {
                    pq.emplace(0, j + 1);
                    now.emplace_back(j + 1);
                }
            }
            vis.assign(n + 1, false);
            ll close = 0;
            while (!pq.empty()) {
                auto [d1, u] = pq.top();
                pq.pop();
                if (vis[u]) {
                    continue;
                }
                vis[u] = true;
                d1 = -d1;
                close = max(close, d1);
                for (auto [v, d2]: g[u]) {
                    if (!vis[v]) {
                        pq.emplace(-d1 - d2, v);
                    }
                }
            }
            if (ans > close) {
                ans = close;
                built = now;
            }
        }
        cout << ans << '\n';
        for (int x: built) {
            cout << x << ' ';
        }
        return;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);

    int queries = 1;
#ifdef test_cases
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
//    cin >> queries;
#else
    //    cin >> queries;
#endif

    for (int test_case = 1; test_case <= queries; test_case++) {
        solve();
//        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 16 ms 320 KB Output is correct
7 Correct 18 ms 212 KB Output is correct
8 Correct 8 ms 340 KB Output is correct
9 Correct 78 ms 212 KB Output is correct
10 Correct 8 ms 212 KB Output is correct
11 Correct 43 ms 320 KB Output is correct
12 Correct 90 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 39 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 13408 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 15300 KB Unexpected end of file - int64 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 3 ms 212 KB Output is correct
5 Correct 3 ms 212 KB Output is correct
6 Correct 16 ms 320 KB Output is correct
7 Correct 18 ms 212 KB Output is correct
8 Correct 8 ms 340 KB Output is correct
9 Correct 78 ms 212 KB Output is correct
10 Correct 8 ms 212 KB Output is correct
11 Correct 43 ms 320 KB Output is correct
12 Correct 90 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 39 ms 316 KB Output is correct
15 Incorrect 45 ms 13408 KB Unexpected end of file - int64 expected
16 Halted 0 ms 0 KB -