結果

問題 No.2677 Minmax Independent Set
ユーザー maeshunmaeshun
提出日時 2024-03-15 23:37:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,078 bytes
コンパイル時間 4,719 ms
コンパイル使用メモリ 265,928 KB
実行使用メモリ 116,692 KB
最終ジャッジ日時 2024-03-15 23:38:20
合計ジャッジ時間 20,089 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
19,924 KB
testcase_01 AC 20 ms
19,924 KB
testcase_02 AC 20 ms
19,924 KB
testcase_03 AC 20 ms
19,924 KB
testcase_04 AC 20 ms
19,924 KB
testcase_05 AC 387 ms
39,636 KB
testcase_06 AC 393 ms
41,300 KB
testcase_07 AC 403 ms
42,708 KB
testcase_08 AC 398 ms
45,908 KB
testcase_09 AC 393 ms
51,796 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 455 ms
116,692 KB
testcase_13 AC 480 ms
68,184 KB
testcase_14 AC 427 ms
71,456 KB
testcase_15 AC 473 ms
85,944 KB
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 306 ms
48,812 KB
testcase_29 AC 471 ms
83,412 KB
testcase_30 AC 20 ms
19,924 KB
testcase_31 AC 20 ms
19,924 KB
testcase_32 AC 20 ms
19,924 KB
testcase_33 AC 20 ms
19,924 KB
testcase_34 AC 21 ms
19,924 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 126 ms
30,820 KB
testcase_51 AC 27 ms
20,820 KB
testcase_52 AC 276 ms
43,804 KB
testcase_53 AC 248 ms
42,024 KB
testcase_54 AC 25 ms
20,564 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 222 ms
29,908 KB
testcase_61 WA -
testcase_62 AC 258 ms
52,948 KB
testcase_63 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint;
using P = pair<ll,ll>;
using lb = long double;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int n;
vector<vector<int>> dp(2e5+5, vector<int>(2));
vector<int> ans(2e5+5);
vector<vector<int>> g(2e5+5);
int m;


//0 白
vector<int> dfs(int u, int p=-1) {
    dp[u][0] = 0;
    dp[u][1] = 1;
    for(int v : g[u]){
        if(v==p) continue;
        dfs(v,u);
        dp[u][0] += max(dp[v][0], dp[v][1]);
        dp[u][1] += dp[v][0];
    }
    return dp[u];
};

void dfs2(int u, int p=-1){
    int N = g[u].size();
    if(N==0) return;
    vector<vector<int>> l(N, vector<int>(2));
    vector<vector<int>> r(N, vector<int>(2));
    rep(i,N){
        ans[u] += dp[g[u][i]][0];
    }
    l[0] = dp[g[u][0]];
    r[N-1] = dp[g[u][N-1]];
    rep(i,N){
        int v = g[u][i];
        if(i-1>=0) {
            l[i][0] = l[i-1][0]+dp[v][0];
            l[i][1] = l[i-1][1]+max(dp[v][0],dp[v][1]);
        }
    }
    for(int i=N-1;i>=0;i--){
        int v = g[u][i];
        if(i+1<N) {
            r[i][0] = r[i+1][0]+dp[v][0];
            r[i][1] = r[i+1][1]+max(dp[v][0],dp[v][1]);
        }
    }
    rep(i,N){
        int v = g[u][i];
        if(v==p) continue;
        dp[u][0] = 0;
        dp[u][1] = 1;
        if(i-1>=0) {
            dp[u][1] += l[i-1][0];
            dp[u][0] += l[i-1][1];
        }
        if(i+1<N) {
            dp[u][1] += r[i+1][0];
            dp[u][0] += r[i+1][1];
        }
        dfs2(v, u);
    }
};

int main()
{
    cin >> n;
    rep(i,n-1){
        int u, v;
        cin >> u >> v;
        --u;--v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0);
    rep(i,n){
        dbg(dp[i]);
    }
    dfs2(0);
    cout<<*min_element(ans.begin(),ans.begin()+n)+1<<endl;
    return 0;
}
0