結果

問題 No.2532 Want Play More
ユーザー 沙耶花
提出日時 2023-11-03 22:01:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 3,683 ms
コンパイル使用メモリ 250,892 KB
最終ジャッジ日時 2025-02-17 18:16:26
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

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