結果

問題 No.2532 Want Play More
ユーザー cho435cho435
提出日時 2023-11-03 23:44:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 611 bytes
コンパイル時間 4,526 ms
コンパイル使用メモリ 265,544 KB
実行使用メモリ 39,184 KB
最終ジャッジ日時 2023-11-03 23:44:37
合計ジャッジ時間 8,447 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,852 KB
testcase_01 AC 235 ms
14,368 KB
testcase_02 AC 244 ms
14,368 KB
testcase_03 AC 233 ms
14,104 KB
testcase_04 AC 211 ms
14,104 KB
testcase_05 AC 197 ms
13,840 KB
testcase_06 AC 174 ms
39,184 KB
testcase_07 AC 6 ms
7,852 KB
testcase_08 AC 10 ms
8,296 KB
testcase_09 AC 9 ms
8,296 KB
testcase_10 AC 100 ms
10,936 KB
testcase_11 AC 87 ms
10,936 KB
testcase_12 AC 154 ms
12,784 KB
testcase_13 AC 112 ms
11,464 KB
testcase_14 AC 35 ms
9,088 KB
testcase_15 AC 224 ms
14,368 KB
testcase_16 AC 180 ms
13,312 KB
testcase_17 AC 9 ms
8,296 KB
testcase_18 AC 138 ms
12,256 KB
testcase_19 AC 216 ms
13,576 KB
testcase_20 AC 5 ms
7,852 KB
testcase_21 AC 4 ms
7,852 KB
testcase_22 AC 4 ms
7,852 KB
testcase_23 AC 4 ms
7,852 KB
testcase_24 AC 4 ms
7,852 KB
testcase_25 AC 4 ms
7,852 KB
testcase_26 AC 3 ms
7,852 KB
testcase_27 AC 3 ms
7,852 KB
testcase_28 AC 113 ms
16,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

vector<vector<int>> g(2e5);
int dfs(int x,int mx,int par=-1){
	vector<int> v;
	for(auto y:g.at(x)){
		if(y==par) continue;
		v.push_back(dfs(y,mx^1,x));
	}
	if(v.empty()) return 0;
	sort(v.begin(),v.end());
	if(mx) return v.back()+1;
	return v.front()+1;
}

int main(){
	int n;
	cin>>n;
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--; b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
	cout<<dfs(0,1)<<endl;
	cout<<dfs(0,0)<<endl;
}
0