結果

問題 No.763 Noelちゃんと木遊び
ユーザー puni_kyopropuni_kyopro
提出日時 2019-10-19 16:04:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 3,046 bytes
コンパイル時間 964 ms
コンパイル使用メモリ 104,364 KB
実行使用メモリ 17,104 KB
最終ジャッジ日時 2023-09-09 13:09:37
合計ジャッジ時間 2,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
17,104 KB
testcase_01 AC 17 ms
8,424 KB
testcase_02 AC 37 ms
10,228 KB
testcase_03 AC 26 ms
9,100 KB
testcase_04 AC 19 ms
8,648 KB
testcase_05 AC 24 ms
9,188 KB
testcase_06 AC 45 ms
10,632 KB
testcase_07 AC 44 ms
10,688 KB
testcase_08 AC 28 ms
9,220 KB
testcase_09 AC 18 ms
8,588 KB
testcase_10 AC 10 ms
7,868 KB
testcase_11 AC 44 ms
10,640 KB
testcase_12 AC 39 ms
10,488 KB
testcase_13 AC 42 ms
10,384 KB
testcase_14 AC 39 ms
9,964 KB
testcase_15 AC 25 ms
9,164 KB
testcase_16 AC 7 ms
7,908 KB
testcase_17 AC 25 ms
9,168 KB
testcase_18 AC 46 ms
10,680 KB
testcase_19 AC 40 ms
10,380 KB
testcase_20 AC 42 ms
10,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>
#include<stack>

#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(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;

int dy[8] = { 2,2,-2,-2,1,1,-1,-1 };
int dx[8] = { 1,-1,1,-1,2,-2,2,-2 };



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
constexpr ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

// vector
template <typename T>
istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }
// pair
template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }
// vector
template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }
// map
template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }
// set
template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }


ll dp[100005][2];
vector<int> G[100005];

void dfs(int now, int pa = -1) {

	for (int to : G[now]) {

		if (to == pa)continue;
		dfs(to, now);
		dp[now][0] += max(dp[to][0] - 1, dp[to][1]);
		dp[now][1] += max(dp[to][0], dp[to][1]);
	}
}


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	
	for (int i = 0; i < 100005; i++)
	{
		dp[i][0] = 1;
		dp[i][1] = 0;
	}
	vector<int> X(N), Y(N);

	for (int i = 0; i < N - 1; i++)
	{
		cin >> X[i] >> Y[i];
		X[i]--;
		Y[i]--;
		G[X[i]].push_back(Y[i]);
		G[Y[i]].push_back(X[i]);
	}

	dfs(0);

	cout << max(dp[0][0], dp[0][1]) << endl;
}
0