結果
| 問題 | No.763 Noelちゃんと木遊び | 
| コンテスト | |
| ユーザー |  ngtkana | 
| 提出日時 | 2020-04-01 22:23:32 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 60 ms / 2,000 ms | 
| コード長 | 835 bytes | 
| コンパイル時間 | 2,037 ms | 
| コンパイル使用メモリ | 200,680 KB | 
| 実行使用メモリ | 14,080 KB | 
| 最終ジャッジ日時 | 2025-03-22 10:37:37 | 
| 合計ジャッジ時間 | 4,152 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 22 | 
ソースコード
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<std::vector<lint>>g(n);
    for(lint i=0;i<n-1;i++){
        lint u,v;std::cin>>u>>v;u--,v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }
    std::vector<std::pair<lint,lint>>dp(n,std::pair{0,1});
    auto dfs=[&](auto&&f,lint x,lint p)->void{
        for(lint y:g.at(x)){
            if(y==p)continue;
            f(f,y,x);
            auto&&[a,b]=dp.at(y);
            std::get<0>(dp.at(x))+=std::max(a,b);
            std::get<1>(dp.at(x))+=a;
        }
    };
    dfs(dfs,0,0);
    std::cout<<std::max(std::get<0>(dp.at(0)),std::get<1>(dp.at(0)))<<'\n';
}
            
            
            
        