結果

問題 No.763 Noelちゃんと木遊び
ユーザー ngtkanangtkana
提出日時 2020-04-01 22:23:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,153 ms
コンパイル使用メモリ 207,808 KB
実行使用メモリ 13,892 KB
最終ジャッジ日時 2023-09-09 18:58:04
合計ジャッジ時間 4,807 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
13,892 KB
testcase_01 AC 15 ms
5,672 KB
testcase_02 AC 33 ms
8,740 KB
testcase_03 AC 22 ms
6,892 KB
testcase_04 AC 17 ms
5,836 KB
testcase_05 AC 22 ms
6,960 KB
testcase_06 AC 40 ms
10,120 KB
testcase_07 AC 37 ms
9,844 KB
testcase_08 AC 24 ms
7,416 KB
testcase_09 AC 15 ms
5,832 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 39 ms
10,400 KB
testcase_12 AC 35 ms
9,624 KB
testcase_13 AC 34 ms
9,316 KB
testcase_14 AC 31 ms
8,804 KB
testcase_15 AC 22 ms
7,068 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 22 ms
6,896 KB
testcase_18 AC 39 ms
10,164 KB
testcase_19 AC 35 ms
9,584 KB
testcase_20 AC 36 ms
9,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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';
}
0