結果

問題 No.763 Noelちゃんと木遊び
ユーザー veqccveqcc
提出日時 2019-02-18 23:26:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 1,017 ms
コンパイル使用メモリ 95,596 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-17 04:46:26
合計ジャッジ時間 3,127 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
13,696 KB
testcase_01 AC 17 ms
6,784 KB
testcase_02 AC 43 ms
8,448 KB
testcase_03 AC 28 ms
7,680 KB
testcase_04 AC 19 ms
7,296 KB
testcase_05 AC 26 ms
7,424 KB
testcase_06 AC 55 ms
8,960 KB
testcase_07 AC 53 ms
8,832 KB
testcase_08 AC 29 ms
7,680 KB
testcase_09 AC 20 ms
7,168 KB
testcase_10 AC 9 ms
6,272 KB
testcase_11 AC 58 ms
8,960 KB
testcase_12 AC 46 ms
8,704 KB
testcase_13 AC 47 ms
8,576 KB
testcase_14 AC 44 ms
8,320 KB
testcase_15 AC 27 ms
7,552 KB
testcase_16 AC 7 ms
6,272 KB
testcase_17 AC 27 ms
7,424 KB
testcase_18 AC 51 ms
8,960 KB
testcase_19 AC 44 ms
8,704 KB
testcase_20 AC 47 ms
8,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;
typedef pair<int, int> P;

int n;
bool visited[100005];
vector <int> edge[100005];

P dfs(int x) {
    visited[x] = true;

    P ret = P(1, 0);

    for (int i: edge[x]) {
        if (visited[i]) continue;

        P p = dfs(i);
        ret.first += max(p.first - 1, p.second);
        ret.second += max(p.first, p.second);
    }

    return ret;
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(0);

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

    P p = dfs(0);
    cout << max(p.first, p.second) << "\n";
    return 0;
}
0