結果

問題 No.763 Noelちゃんと木遊び
ユーザー beetbeet
提出日時 2019-03-03 17:42:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 3,331 ms
コンパイル使用メモリ 203,432 KB
実行使用メモリ 17,900 KB
最終ジャッジ日時 2023-09-05 17:47:25
合計ジャッジ時間 5,358 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
17,900 KB
testcase_01 AC 28 ms
5,836 KB
testcase_02 AC 66 ms
8,804 KB
testcase_03 AC 45 ms
6,904 KB
testcase_04 AC 33 ms
6,024 KB
testcase_05 AC 43 ms
7,032 KB
testcase_06 AC 87 ms
10,196 KB
testcase_07 AC 83 ms
9,916 KB
testcase_08 AC 47 ms
7,452 KB
testcase_09 AC 30 ms
6,096 KB
testcase_10 AC 12 ms
4,376 KB
testcase_11 AC 88 ms
10,384 KB
testcase_12 AC 79 ms
9,552 KB
testcase_13 AC 74 ms
9,356 KB
testcase_14 AC 65 ms
8,880 KB
testcase_15 AC 44 ms
6,964 KB
testcase_16 AC 9 ms
4,384 KB
testcase_17 AC 46 ms
6,948 KB
testcase_18 AC 88 ms
10,128 KB
testcase_19 AC 77 ms
9,712 KB
testcase_20 AC 77 ms
9,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
Int dp[2][114514];
signed main(){
  Int n;
  cin>>n;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  function<void(Int, Int)> dfs=
    [&](Int v,Int p)->void{
      for(Int u:G[v]){
        if(u!=p) dfs(u,v);
      }
      dp[0][v]=0;
      dp[1][v]=0;
      for(Int u:G[v]){
        if(u==p) continue;
        dp[0][v]+=max(dp[0][u],dp[1][u]);
        dp[1][v]+=max(dp[0][u]+1,dp[1][u]);
      }
    };
  dfs(0,-1);
  cout<<max(dp[0][0]+1,dp[1][0])<<endl;
  return 0;
}
0