結果
問題 | No.763 Noelちゃんと木遊び |
ユーザー |
![]() |
提出日時 | 2022-10-25 11:59:15 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 2,000 ms |
コード長 | 1,981 bytes |
コンパイル時間 | 2,739 ms |
コンパイル使用メモリ | 254,020 KB |
実行使用メモリ | 22,016 KB |
最終ジャッジ日時 | 2024-07-03 11:51:20 |
合計ジャッジ時間 | 5,421 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;using ull = unsigned long long;using ld = long double;template<class t> using vc = vector<t>;template<class t> using vvc = vc<vc<t>>;using pi = pair<int,int>;using pl = pair<ll,ll>;using vi = vc<int>;using vvi = vvc<int>;using vl = vc<ll>;using vvl = vvc<ll>;#define rep(i,a,b) for (int i = (int)(a); i < (int)(b); i++)#define irep(i,a,b) for (int i = (int)(a); i > (int)(b); i--)#define all(a) a.begin(),a.end()#define print(n) cout << n << '\n'#define pritn(n) print(n)#define printv(n,a) {copy(all(n),ostream_iterator<a>(cout," ")); cout<<"\n";}#define printvv(n,a) {for(auto itr:n) printv(itr,a);}#define rup(a,b) (a+b-1)/b#define input(A,N) rep(i,0,N) cin>>A[i]#define chmax(a,b) a = max(a,b)#define chmin(a,b) a = min(a,b)template< typename T >struct edge{int from,to;T cost;/**to:繋がってる先*cost:辺のコスト*/edge(int from,int to, T cost):from(from),to(to),cost(cost){};edge &operator=(const int& x){to = x;return *this;}};template< typename T >struct graph{int n;vector<vector<edge<T>>> e;graph(int n):n(n),e(n){}void addedge(int from,int to,T cost){e[from].emplace_back(from,to,cost);}vector<edge<T>> &operator[](int i) {return e[i];}};void dfs(int ni,int par,vvi&dp,graph<int>&g){for(auto e:g[ni]){if(par==e.to) continue;dfs(e.to,ni,dp,g);dp[ni][0] += max(dp[e.to][0],dp[e.to][1]);dp[ni][1] += dp[e.to][0];}dp[ni][1] ++;return ;}int main(){cout << fixed << setprecision(15);int n;cin>>n;graph<int> g(n);rep(i,0,n-1){int u,v;cin>>u>>v;u--;v--;g.addedge(u,v,1);g.addedge(v,u,1);}vvi dp(n,vi(2,0));dfs(0,-1,dp,g);print(max(dp[0][0],dp[0][1]));//system("pause");return 0;}