結果

問題 No.2677 Minmax Independent Set
ユーザー NokonoKotlinNokonoKotlin
提出日時 2024-03-13 21:03:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,230 bytes
コンパイル時間 3,091 ms
コンパイル使用メモリ 259,328 KB
実行使用メモリ 28,420 KB
最終ジャッジ日時 2024-03-15 20:55:45
合計ジャッジ時間 67,574 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1,515 ms
17,220 KB
testcase_11 AC 1,514 ms
17,220 KB
testcase_12 AC 1,528 ms
28,420 KB
testcase_13 AC 1,516 ms
22,544 KB
testcase_14 AC 1,528 ms
20,624 KB
testcase_15 AC 1,517 ms
23,144 KB
testcase_16 AC 1,519 ms
16,736 KB
testcase_17 WA -
testcase_18 AC 1,511 ms
11,680 KB
testcase_19 AC 1,514 ms
13,992 KB
testcase_20 AC 1,505 ms
6,912 KB
testcase_21 AC 1,513 ms
14,904 KB
testcase_22 AC 1,504 ms
6,548 KB
testcase_23 AC 7 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 5 ms
6,548 KB
testcase_28 AC 1,516 ms
17,300 KB
testcase_29 AC 1,533 ms
28,280 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 2 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 2 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 3 ms
6,548 KB
testcase_38 AC 7 ms
6,548 KB
testcase_39 AC 33 ms
6,548 KB
testcase_40 AC 170 ms
6,548 KB
testcase_41 AC 824 ms
6,548 KB
testcase_42 AC 1,503 ms
6,548 KB
testcase_43 AC 1,505 ms
6,548 KB
testcase_44 AC 1,507 ms
6,656 KB
testcase_45 AC 1,508 ms
9,964 KB
testcase_46 AC 1,518 ms
16,392 KB
testcase_47 AC 1,534 ms
16,576 KB
testcase_48 WA -
testcase_49 AC 1,533 ms
16,576 KB
testcase_50 AC 1,506 ms
9,000 KB
testcase_51 AC 273 ms
6,548 KB
testcase_52 AC 1,512 ms
15,300 KB
testcase_53 AC 1,508 ms
14,540 KB
testcase_54 AC 168 ms
6,548 KB
testcase_55 AC 1,519 ms
17,344 KB
testcase_56 AC 1,518 ms
17,324 KB
testcase_57 AC 1,521 ms
17,328 KB
testcase_58 AC 1,520 ms
17,336 KB
testcase_59 AC 1,514 ms
17,324 KB
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 次数が大きい順に試していくヒューリスティック
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> adj;

// 木DPを行う
pair<int, int> rec(int r, int par = -1) {
    int ret0 = 0;
    int ret1 = 1;

    for (auto &&c : adj[r]) {
        if (c == par) continue;
        auto [dp0, dp1] = rec(c, r);
        ret0 += max(dp0, dp1);
        ret1 += dp0;
    }

    return {ret0, ret1};
}

int main() {
    auto start = chrono::system_clock::now();

    int N;
    cin >> N;

    adj.resize(N);

    for (int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vector<pair<int, int>> order;
    for (int i = 0; i < N; i++) {
        order.push_back({adj[i].size(), i});
    }
    sort(order.begin(), order.end(), greater<pair<int, int>>());

    int ans = numeric_limits<int>::max();

    for (auto &&[_, r] : order) {
        auto now = chrono::system_clock::now();
        auto ms = chrono::duration_cast<std::chrono::milliseconds>(now - start).count();

        if (ms > 1500) break;

        auto [dp0, dp1] = rec(r);

        ans = min(ans, dp1);
    }

    cout << ans << endl;
}
0