結果

問題 No.763 Noelちゃんと木遊び
ユーザー TiramisterTiramister
提出日時 2018-12-20 19:51:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 786 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 73,144 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2023-10-26 01:11:31
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
18,560 KB
testcase_01 AC 28 ms
7,088 KB
testcase_02 AC 63 ms
8,552 KB
testcase_03 AC 44 ms
7,736 KB
testcase_04 AC 32 ms
7,236 KB
testcase_05 AC 42 ms
7,676 KB
testcase_06 AC 75 ms
9,096 KB
testcase_07 AC 73 ms
8,984 KB
testcase_08 AC 45 ms
7,816 KB
testcase_09 AC 30 ms
7,196 KB
testcase_10 AC 14 ms
6,464 KB
testcase_11 AC 78 ms
9,156 KB
testcase_12 AC 71 ms
8,800 KB
testcase_13 AC 69 ms
8,752 KB
testcase_14 AC 58 ms
8,456 KB
testcase_15 AC 42 ms
7,704 KB
testcase_16 AC 10 ms
6,284 KB
testcase_17 AC 43 ms
7,724 KB
testcase_18 AC 77 ms
9,116 KB
testcase_19 AC 67 ms
8,832 KB
testcase_20 AC 69 ms
8,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

vector<int> path[100010];
bool visited[100010];

pair<int, int> dfs(int v) {
    visited[v] = true;

    vector<pair<int, int>> res;
    for (int sv : path[v]) {
        if (visited[sv]) continue;

        res.push_back(dfs(sv));
    }

    pair<int, int> ret = make_pair(0, 1);
    for (auto p : res) {
        ret.first += max(p.first, p.second);
        ret.second += max(p.first, p.second - 1);
    }

    return ret;
}

int main() {
    int N;
    cin >> N;

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

    pair<int, int> ret = dfs(0);
    cout << max(ret.first, ret.second) << endl;
    return 0;
}
0