結果

問題 No.763 Noelちゃんと木遊び
ユーザー drken1215drken1215
提出日時 2018-02-22 00:09:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 819 ms
コンパイル使用メモリ 69,952 KB
実行使用メモリ 17,988 KB
最終ジャッジ日時 2023-10-24 22:14:49
合計ジャッジ時間 3,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
17,988 KB
testcase_01 AC 26 ms
7,728 KB
testcase_02 AC 60 ms
9,496 KB
testcase_03 AC 41 ms
8,508 KB
testcase_04 AC 30 ms
7,912 KB
testcase_05 AC 39 ms
8,444 KB
testcase_06 AC 73 ms
10,088 KB
testcase_07 AC 69 ms
9,976 KB
testcase_08 AC 43 ms
8,608 KB
testcase_09 AC 29 ms
7,860 KB
testcase_10 AC 13 ms
6,984 KB
testcase_11 AC 73 ms
10,148 KB
testcase_12 AC 66 ms
9,792 KB
testcase_13 AC 63 ms
9,736 KB
testcase_14 AC 57 ms
9,376 KB
testcase_15 AC 40 ms
8,476 KB
testcase_16 AC 8 ms
6,760 KB
testcase_17 AC 40 ms
8,492 KB
testcase_18 AC 72 ms
10,104 KB
testcase_19 AC 66 ms
9,828 KB
testcase_20 AC 67 ms
9,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

const int MAX = 110000;
int N;
vector<int> G[MAX];

int dp[MAX][2];

// 0: v remained, 1: v erased
void rec(int v, int p = -1) {
    dp[v][0] = 1;
    dp[v][1] = 0;
    for (auto ch : G[v]) {
        if (ch == p) continue;
        rec(ch, v);
        dp[v][0] += max(dp[ch][0]-1, dp[ch][1]);
        dp[v][1] += max(dp[ch][0], dp[ch][1]);
    }
    //cout << v << ", " << dp[v][0] << ": " << dp[v][1] << endl;
}

int main() {
    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);
    }
    rec(0);
    cout << max(dp[0][0], dp[0][1]) << endl;
}
0