結果

問題 No.2532 Want Play More
ユーザー 沙耶花沙耶花
提出日時 2023-11-03 22:01:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 4,810 ms
コンパイル使用メモリ 264,088 KB
実行使用メモリ 26,772 KB
最終ジャッジ日時 2023-11-03 22:01:39
合計ジャッジ時間 7,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 211 ms
14,364 KB
testcase_02 AC 217 ms
14,364 KB
testcase_03 AC 239 ms
13,836 KB
testcase_04 AC 200 ms
13,836 KB
testcase_05 AC 187 ms
13,572 KB
testcase_06 AC 160 ms
26,772 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 83 ms
8,624 KB
testcase_11 AC 83 ms
8,360 KB
testcase_12 AC 144 ms
11,460 KB
testcase_13 AC 99 ms
9,416 KB
testcase_14 AC 32 ms
5,456 KB
testcase_15 AC 205 ms
14,364 KB
testcase_16 AC 169 ms
12,516 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 124 ms
10,472 KB
testcase_19 AC 172 ms
12,780 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 1 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 113 ms
15,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001
int n;
vector<vector<int>> E;

int get(int cv,int turn,int pv = -1){
	if(turn==0){
		int ret = -Inf32;
		rep(i,E[cv].size()){
			int to  =E[cv][i];
			if(to==pv)continue;
			ret = max(ret,get(to,1,cv)+1);
		}
		if(ret==-Inf32)ret= 0;
		return ret;
	}
	else{
		int ret = Inf32;
		rep(i,E[cv].size()){
			int to  =E[cv][i];
			if(to==pv)continue;
			ret = min(ret,get(to,0,cv)+1);
		}
		if(ret==Inf32)ret= 0;
		return ret;
	}
}

int main(){
	
	cin>>n;
	E.resize(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--,b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}
	cout<<get(0,0)<<endl;
	cout<<get(0,1)<<endl;
	
	return 0;
}
0