結果

問題 No.2677 Minmax Independent Set
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-15 22:44:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,697 bytes
コンパイル時間 2,686 ms
コンパイル使用メモリ 210,988 KB
実行使用メモリ 133,872 KB
最終ジャッジ日時 2024-03-15 22:45:06
合計ジャッジ時間 16,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 RE -
testcase_04 AC 2 ms
6,676 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 419 ms
133,872 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 290 ms
42,384 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 3 ms
6,676 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 355 ms
37,188 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 141 ms
37,756 KB
testcase_61 WA -
testcase_62 AC 167 ms
56,304 KB
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

    int N; cin >> N;
    vector<vector<int>> Graph(N);
    for(int i=0; i<N-1; i++){
        int u,v; cin >> u >> v;
        u--; v--;
        Graph.at(u).push_back(v);
        Graph.at(v).push_back(u);
    }

    vector<vector<int>> ko1(N),ko2(N);
    vector<int> par(N,-1);
auto d1 = [&](auto d1,int pos,int back) -> pair<int,int> {
    int w = 0,b = 1;
    int siz = Graph.at(pos).size();
    for(int i=0; i<siz; i++){
        int to = Graph.at(pos).at(i);
        if(to == back){par.at(pos) = i; ko1.at(pos).push_back(0),ko2.at(pos).push_back(0); continue;}

        auto[kow,kob] = d1(d1,to,pos);
        ko1.at(pos).push_back(max(kow,kob)),ko2.at(pos).push_back(kow);
        w += max(kow,kob),b += kow;
    }
    return {w,b};
};
    d1(d1,0,-1);

    int answer = 1e9;
auto d2 = [&](auto d2,int pos,int back,int pw,int pb) -> void {
    if(back != -1) ko1.at(pos).at(par.at(pos)) = max(pw,pb), ko2.at(pos).at(par.at(pos)) = pb;
    int siz = Graph.at(pos).size();

    vector<int> l1 = ko1.at(pos),r1 = ko1.at(pos),l2 = ko2.at(pos),r2 = ko2.at(pos);
    for(int i=1; i<siz; i++) l1.at(i) += l1.at(i-1),l2.at(i) += l2.at(i-1);
    for(int i=siz-2; i>=0; i--) r1.at(i) += r1.at(i+1),r2.at(i) += r2.at(i+1);
    answer = min(answer,l2.back()+1);

    for(int i=0; i<siz; i++){
        int to = Graph.at(pos).at(i);
        if(to == back) continue;

        int gw = 0,gb = 1;
        if(i) gw += l1.at(i-1),gb += l2.at(i-1);
        if(i != siz-1) gw += r1.at(i+1),gb += r2.at(i+1);
        d2(d2,to,pos,gw,gb);
    }
};
    d2(d2,0,-1,0,0);
    cout << answer << endl;
}
0