結果

問題 No.763 Noelちゃんと木遊び
ユーザー 👑 jupirojupiro
提出日時 2020-02-01 14:30:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,580 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 120,220 KB
実行使用メモリ 22,068 KB
最終ジャッジ日時 2023-10-19 00:00:15
合計ジャッジ時間 4,485 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
22,068 KB
testcase_01 AC 20 ms
7,020 KB
testcase_02 AC 53 ms
11,772 KB
testcase_03 AC 32 ms
9,132 KB
testcase_04 AC 22 ms
7,548 KB
testcase_05 AC 31 ms
9,132 KB
testcase_06 AC 72 ms
13,620 KB
testcase_07 AC 69 ms
13,356 KB
testcase_08 AC 33 ms
9,396 KB
testcase_09 AC 22 ms
7,284 KB
testcase_10 AC 10 ms
4,908 KB
testcase_11 AC 72 ms
13,884 KB
testcase_12 AC 59 ms
12,828 KB
testcase_13 AC 58 ms
12,564 KB
testcase_14 AC 49 ms
11,508 KB
testcase_15 AC 32 ms
9,132 KB
testcase_16 AC 6 ms
4,380 KB
testcase_17 AC 32 ms
9,132 KB
testcase_18 AC 71 ms
13,884 KB
testcase_19 AC 65 ms
12,828 KB
testcase_20 AC 62 ms
12,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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 long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int n;
vector<vector<int>> g;
vector<vector<int>> dp;

void dfs(int cur, int pre) {
	for (auto next : g[cur]) {
		if (next == pre) continue;
		dfs(next, cur);
	}
	int re = 1;
	int er = 0;
	for (auto next : g[cur]) {
		if (next == pre) continue;
		er += max(dp[next][0], dp[next][1]);
		re += max(dp[next][0] - 1, dp[next][1]);
	}
	dp[cur][0] = re;
	dp[cur][1] = er;
}

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d", &n);
	g = vector<vector<int>>(n);
	dp = vector<vector<int>>(n, vector<int>(2));
	for (int i = 0; i < n - 1; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		u--; v--;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	dfs(0, -1);
	cout << max(dp[0][0], dp[0][1]) << endl;
	return 0;
}
0