結果

問題 No.2532 Want Play More
ユーザー ripityripity
提出日時 2023-11-03 23:10:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 209,052 KB
実行使用メモリ 34,552 KB
最終ジャッジ日時 2023-11-03 23:10:17
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 247 ms
25,312 KB
testcase_02 AC 244 ms
25,312 KB
testcase_03 AC 255 ms
24,256 KB
testcase_04 AC 235 ms
24,256 KB
testcase_05 AC 234 ms
23,464 KB
testcase_06 AC 167 ms
34,552 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 106 ms
13,568 KB
testcase_11 AC 103 ms
13,304 KB
testcase_12 AC 169 ms
19,572 KB
testcase_13 AC 134 ms
15,416 KB
testcase_14 AC 35 ms
7,232 KB
testcase_15 AC 272 ms
25,048 KB
testcase_16 AC 210 ms
21,616 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 150 ms
17,460 KB
testcase_19 AC 208 ms
22,144 KB
testcase_20 AC 2 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 2 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 128 ms
25,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
	int N;
	cin >> N;
	vector<vector<int>> G(N);
	for( int i = 0; i < N-1; i++ ) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<vector<int>> dp(N, vector<int>(2));
	for( int i = 0; i < N; i++ ) {
		dp[i][0] = 0;
		dp[i][1] = ( i != 0 && G[i].size() == 1 ? 0 : N-1 );
	}
	auto dfs = [&](auto dfs, int cur, int pre) -> void {
		for( int &nxt : G[cur] ) {
			if( nxt != pre ) dfs(dfs, nxt, cur);
		}
		if( pre != -1 ) {
			dp[pre][0] = max(dp[pre][0], dp[cur][1]+1);
			dp[pre][1] = min(dp[pre][1], dp[cur][0]+1);
		}
	};
	dfs(dfs, 0, -1);
	cout << dp[0][0] << endl;
	cout << dp[0][1] << endl;
}
0