結果

問題 No.763 Noelちゃんと木遊び
ユーザー kenken714kenken714
提出日時 2019-03-23 20:32:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 84,716 KB
実行使用メモリ 20,840 KB
最終ジャッジ日時 2023-10-24 22:48:19
合計ジャッジ時間 3,499 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
20,840 KB
testcase_01 AC 31 ms
10,116 KB
testcase_02 AC 72 ms
12,444 KB
testcase_03 AC 47 ms
11,148 KB
testcase_04 AC 34 ms
10,356 KB
testcase_05 AC 46 ms
11,060 KB
testcase_06 AC 92 ms
13,312 KB
testcase_07 AC 86 ms
13,136 KB
testcase_08 AC 51 ms
11,276 KB
testcase_09 AC 34 ms
10,292 KB
testcase_10 AC 15 ms
9,132 KB
testcase_11 AC 93 ms
13,412 KB
testcase_12 AC 81 ms
12,844 KB
testcase_13 AC 80 ms
12,764 KB
testcase_14 AC 70 ms
12,288 KB
testcase_15 AC 48 ms
11,104 KB
testcase_16 AC 10 ms
8,840 KB
testcase_17 AC 48 ms
11,128 KB
testcase_18 AC 92 ms
13,340 KB
testcase_19 AC 85 ms
12,888 KB
testcase_20 AC 84 ms
12,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

#include <iostream>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, dp[110000][2];
vector<ll> e[200000];

void dfs(ll a, ll b) {
	REP(i, e[a].size()) {
		if (e[a][i] != b) {
			dfs(e[a][i], a);
			dp[a][0] += max(dp[e[a][i]][0], dp[e[a][i]][1]);
			dp[a][1] += max(dp[e[a][i]][0], dp[e[a][i]][1] - 1);
		}
	}
	dp[a][1]++;
}

int main() {
	cin >> n;
	REP(i, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	dfs(0, 0);
	cout << max(dp[0][0], dp[0][1]) << endl;
}
0