結果

問題 No.763 Noelちゃんと木遊び
ユーザー parukiparuki
提出日時 2018-12-24 09:42:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,168 bytes
コンパイル時間 1,594 ms
コンパイル使用メモリ 169,884 KB
実行使用メモリ 17,700 KB
最終ジャッジ日時 2023-10-26 02:57:37
合計ジャッジ時間 3,150 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
17,700 KB
testcase_01 AC 15 ms
7,848 KB
testcase_02 AC 31 ms
9,272 KB
testcase_03 AC 22 ms
8,476 KB
testcase_04 AC 17 ms
7,996 KB
testcase_05 AC 22 ms
8,424 KB
testcase_06 AC 38 ms
9,800 KB
testcase_07 AC 36 ms
9,688 KB
testcase_08 AC 23 ms
8,556 KB
testcase_09 AC 15 ms
7,956 KB
testcase_10 AC 8 ms
7,248 KB
testcase_11 AC 38 ms
9,860 KB
testcase_12 AC 34 ms
9,512 KB
testcase_13 AC 33 ms
9,464 KB
testcase_14 AC 29 ms
9,176 KB
testcase_15 AC 21 ms
8,452 KB
testcase_16 AC 5 ms
7,068 KB
testcase_17 AC 21 ms
8,464 KB
testcase_18 AC 37 ms
9,816 KB
testcase_19 AC 34 ms
9,540 KB
testcase_20 AC 34 ms
9,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int N;
vi G[100005];

int dp[100005][2];
int f(int u, int p, int flag) {
    int &re = dp[u][flag];
    if (re != -1)RT re;
    int s = 0, t = 0;
    each(v, G[u])if (v != p) {
        s += f(v, u, 1);
        t += f(v, u, 0);
    }
    return re = max(s + (1 - flag), t);
}

void solve() {
    cin >> N;
    rep(i, N - 1) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    MEM(dp, -1);
    cout << f(1, 0, 0) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0