結果

問題 No.2532 Want Play More
ユーザー shobonvipshobonvip
提出日時 2023-11-03 22:12:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 1,941 bytes
コンパイル時間 4,482 ms
コンパイル使用メモリ 264,696 KB
実行使用メモリ 38,392 KB
最終ジャッジ日時 2023-11-03 22:13:04
合計ジャッジ時間 8,846 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 274 ms
16,744 KB
testcase_02 AC 259 ms
16,744 KB
testcase_03 AC 224 ms
16,216 KB
testcase_04 AC 219 ms
16,216 KB
testcase_05 AC 241 ms
15,688 KB
testcase_06 AC 166 ms
38,392 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 8 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 88 ms
9,684 KB
testcase_11 AC 86 ms
9,420 KB
testcase_12 AC 150 ms
13,312 KB
testcase_13 AC 102 ms
10,740 KB
testcase_14 AC 31 ms
5,800 KB
testcase_15 AC 208 ms
16,480 KB
testcase_16 AC 218 ms
14,632 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 131 ms
12,060 KB
testcase_19 AC 182 ms
14,896 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 115 ms
17,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n; cin >> n;
	vector ikeru(n, vector<int>(0));
	rep(i,0,n-1){
		int a, b; cin >> a >> b;
		a--; b--;
		ikeru[a].push_back(b);
		ikeru[b].push_back(a);
	}
	vector<int> c(n);
	
	auto dfs = [&](auto self, int i, int p) -> void {
		for (int j: ikeru[i]){
			if (j == p) continue;
			c[j] = c[i] ^ 1;
			self(self, j, i);
		}
	};

	dfs(dfs, 0, -1);


	vector<int> dp1(n);
	vector<int> dp2(n);
	
	auto dfs2 = [&](auto self, int i, int p) -> void {
		if (c[i] == 0){
			dp2[i] = 1e9;
		}else{
			dp1[i] = 1e9;
		}
		for (int j: ikeru[i]){
			if (j == p) continue;
			self(self, j, i);
			if (c[i] == 0){
				chmax(dp1[i], dp1[j] + 1);
				chmin(dp2[i], dp2[j] + 1);
			}else{
				chmax(dp2[i], dp2[j] + 1);
				chmin(dp1[i], dp1[j] + 1);
			}
		}
		if (dp1[i] == 1e9) dp1[i] = 0;
		if (dp2[i] == 1e9) dp2[i] = 0;
	};

	dfs2(dfs2, 0, -1);
	cout << dp1[0] << endl;
	cout << dp2[0] << endl;


}

0