結果

問題 No.763 Noelちゃんと木遊び
ユーザー pionepione
提出日時 2020-07-11 18:25:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 2,105 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 167,732 KB
実行使用メモリ 15,140 KB
最終ジャッジ日時 2023-08-03 11:33:22
合計ジャッジ時間 4,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
15,140 KB
testcase_01 AC 16 ms
7,520 KB
testcase_02 AC 35 ms
10,012 KB
testcase_03 AC 23 ms
8,476 KB
testcase_04 AC 17 ms
7,748 KB
testcase_05 AC 23 ms
8,464 KB
testcase_06 AC 40 ms
10,732 KB
testcase_07 AC 40 ms
10,660 KB
testcase_08 AC 24 ms
8,676 KB
testcase_09 AC 17 ms
7,580 KB
testcase_10 AC 9 ms
6,584 KB
testcase_11 AC 43 ms
10,864 KB
testcase_12 AC 36 ms
10,232 KB
testcase_13 AC 37 ms
10,096 KB
testcase_14 AC 33 ms
9,572 KB
testcase_15 AC 24 ms
8,384 KB
testcase_16 AC 6 ms
6,184 KB
testcase_17 AC 24 ms
8,460 KB
testcase_18 AC 42 ms
10,764 KB
testcase_19 AC 39 ms
10,432 KB
testcase_20 AC 39 ms
10,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

vll G[100100];
ll dp[100100][2];


void dfs(ll v, ll p){
  ll child=0;
  for(auto &nv: G[v]){
    if(nv==p) continue;
    dfs(nv,v);
    dp[v][0]+=max(dp[nv][0],dp[nv][1]);
    dp[v][1]+=max(dp[nv][0]+1,dp[nv][1]);
  }
  // cout<<v<<' '<<dp[v][0]<<' '<<dp[v][1]<<endl;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  rep(i,n-1){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  // rep(i,n) rep(j,2) dp[i][j]=1;
  
  dfs(0,-1);
  cout<<max(dp[0][0]+1,dp[0][1])<<endl;
  
}
0