結果

問題 No.2677 Minmax Independent Set
ユーザー kokoseikokosei
提出日時 2024-03-15 23:51:15
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,631 bytes
コンパイル時間 3,212 ms
コンパイル使用メモリ 252,408 KB
実行使用メモリ 70,656 KB
最終ジャッジ日時 2024-03-15 23:52:11
合計ジャッジ時間 13,139 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 3 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 3 ms
6,676 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 224 ms
31,612 KB
testcase_11 AC 199 ms
31,616 KB
testcase_12 AC 261 ms
70,656 KB
testcase_13 WA -
testcase_14 AC 258 ms
44,892 KB
testcase_15 AC 289 ms
53,008 KB
testcase_16 AC 262 ms
27,648 KB
testcase_17 WA -
testcase_18 AC 157 ms
18,944 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 216 ms
23,680 KB
testcase_22 AC 12 ms
6,676 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 188 ms
32,188 KB
testcase_29 AC 263 ms
54,656 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 3 ms
6,676 KB
testcase_33 WA -
testcase_34 AC 3 ms
6,676 KB
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 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 64 ms
14,172 KB
testcase_51 AC 6 ms
6,676 KB
testcase_52 AC 155 ms
27,164 KB
testcase_53 AC 143 ms
25,320 KB
testcase_54 AC 5 ms
6,676 KB
testcase_55 AC 224 ms
31,536 KB
testcase_56 AC 237 ms
31,468 KB
testcase_57 AC 233 ms
31,828 KB
testcase_58 AC 221 ms
31,800 KB
testcase_59 AC 229 ms
31,540 KB
testcase_60 AC 101 ms
27,648 KB
testcase_61 AC 108 ms
28,160 KB
testcase_62 AC 113 ms
37,504 KB
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int N;
vector<int> G[202020];
vector<pair<int, int>> dp[202020];
pair<int, int> ans[202020];
pair<int, int> add(pair<int, int> a, pair<int, int> b){
    a.first += b.second;
    a.second += max(b.first, b.second);
    return a;
}
pair<int, int> addroot(pair<int, int> p){
    p.first += 1;
    return p;
}
pair<int, int> dfs0(int v, int p){
    pair<int, int> res = {0, 0};
    int sz = G[v].size();
    dp[v].resize(sz);
    for(int i = 0;i < sz;i++){
        int nv = G[v][i];
        if(nv == p)continue;
        dp[v][i] = dfs0(nv, v);
        res = add(res, dp[v][i]);
    }
    return addroot(res);
}
void dfs(int v, pair<int, int> pre, int p){
    int sz = G[v].size();
    for(int i = 0;i < sz;i++){
        if(G[v][i] == p)dp[v][i] = pre;
    }
    vector<pair<int, int>> dpl(sz + 1), dpr(sz + 1);
    for(int i = 0;i < sz;i++){
        dpl[i + 1] = add(dpl[i], dp[v][i]);
    }
    for(int i = sz - 1;i >= 0;i--){
        dpr[i] = add(dpr[i + 1], dp[v][i]);
    }
    ans[v] = addroot(dpl[sz]);
    for(int i = 0;i < sz;i++){
        int nv = G[v][i];
        if(nv == p)continue;
        dfs(nv, addroot(add(dpl[i], dpr[i + 1])), v);
    }
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> N;
    for(int i = 0;i < N - 1;i++){
        int u, v; cin >> u >> v;
        u--, v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs0(0, -1);
    dfs(0, {0, 0}, -1);
    int all = 1e9;
    for(int i = 0;i < N;i++){
        all = min(all, ans[i].first);
    }
    cout << all << endl;
    return 0;
}
0