結果

問題 No.763 Noelちゃんと木遊び
ユーザー veqcc
提出日時 2019-02-18 23:26:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 880 ms
コンパイル使用メモリ 90,756 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2025-03-22 10:35:38
合計ジャッジ時間 3,435 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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

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