結果

問題 No.763 Noelちゃんと木遊び
ユーザー 👑 jupirojupiro
提出日時 2020-03-13 20:24:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,716 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 119,708 KB
実行使用メモリ 22,052 KB
最終ジャッジ日時 2023-08-14 17:57:42
合計ジャッジ時間 4,452 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
22,052 KB
testcase_01 AC 14 ms
6,796 KB
testcase_02 AC 36 ms
11,492 KB
testcase_03 AC 23 ms
8,804 KB
testcase_04 AC 16 ms
7,228 KB
testcase_05 AC 23 ms
8,648 KB
testcase_06 AC 44 ms
13,344 KB
testcase_07 AC 42 ms
13,188 KB
testcase_08 AC 24 ms
9,136 KB
testcase_09 AC 16 ms
7,116 KB
testcase_10 AC 7 ms
4,584 KB
testcase_11 AC 44 ms
13,672 KB
testcase_12 AC 38 ms
12,300 KB
testcase_13 AC 38 ms
12,304 KB
testcase_14 AC 31 ms
11,180 KB
testcase_15 AC 22 ms
8,852 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 22 ms
8,972 KB
testcase_18 AC 42 ms
13,456 KB
testcase_19 AC 39 ms
12,492 KB
testcase_20 AC 39 ms
12,636 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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr 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 (int next : g[cur]) {
		if (next == pre) continue;
		dfs(next, cur);
	}
	int res1 = 1;
	int res2 = 0;
	for (int next : g[cur]) {
		if (next == pre) continue;
		res2 += max(dp[next][0], dp[next][1]);
		res1 += max(dp[next][0] - 1, dp[next][1]);
	}
	dp[cur][0] = res1;
	dp[cur][1] = res2;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d", &n);
	g.resize(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].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	cout << max(dp[0][0], dp[0][1]) << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0