結果

問題 No.95 Alice and Graph
ユーザー maine_honzukimaine_honzuki
提出日時 2020-05-13 18:07:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,250 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 174,192 KB
実行使用メモリ 12,144 KB
最終ジャッジ日時 2023-10-12 17:01:33
合計ジャッジ時間 14,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<int>> d(N, vector<int>(N, 100));
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        d[a][b] = 1;
        d[b][a] = 1;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    vector<int> use{0};
    for (int i = N - 1; i > 0; i--) {
        sort(use.begin(), use.end());
        vector<int> tmp = use;
        tmp.push_back(i);
        sort(tmp.begin(), tmp.end());
        bool flag = false;
        do {
            int cost = 0;
            for (int j = 0; j < (int)tmp.size() - 1; j++) {
                cost += d[tmp[j]][tmp[j + 1]];
            }
            if (cost <= K)
                flag = true;
        } while (next_permutation(tmp.begin() + 1, tmp.end()));
        if (flag) {
            use = tmp;
        }
        if ((int)use.size() == K + 1) {
            break;
        }
    }

    long long ans = 0;
    for (auto& x : use) {
        ans += (1ll << x) - 1;
    }
    cout << ans << endl;
}
0