結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2019-03-03 17:42:41 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 91 ms / 2,000 ms |
コード長 | 820 bytes |
コンパイル時間 | 1,967 ms |
コンパイル使用メモリ | 198,144 KB |
最終ジャッジ日時 | 2025-01-06 21:54:39 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#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 HEREInt 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;}