結果

問題 No.2532 Want Play More
ユーザー keisuke6keisuke6
提出日時 2023-11-03 21:32:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 2,366 ms
コンパイル使用メモリ 205,984 KB
実行使用メモリ 26,716 KB
最終ジャッジ日時 2023-11-03 21:32:28
合計ジャッジ時間 6,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,792 KB
testcase_01 AC 168 ms
15,364 KB
testcase_02 AC 173 ms
15,364 KB
testcase_03 AC 152 ms
15,100 KB
testcase_04 AC 154 ms
14,836 KB
testcase_05 AC 148 ms
14,572 KB
testcase_06 AC 133 ms
26,716 KB
testcase_07 AC 5 ms
7,792 KB
testcase_08 AC 8 ms
8,236 KB
testcase_09 AC 7 ms
8,236 KB
testcase_10 AC 79 ms
11,404 KB
testcase_11 AC 68 ms
11,404 KB
testcase_12 AC 120 ms
13,516 KB
testcase_13 AC 79 ms
11,932 KB
testcase_14 AC 27 ms
9,292 KB
testcase_15 AC 154 ms
15,100 KB
testcase_16 AC 157 ms
14,044 KB
testcase_17 AC 7 ms
8,236 KB
testcase_18 AC 96 ms
12,724 KB
testcase_19 AC 154 ms
14,308 KB
testcase_20 AC 4 ms
7,792 KB
testcase_21 AC 4 ms
7,792 KB
testcase_22 AC 4 ms
7,792 KB
testcase_23 AC 4 ms
7,792 KB
testcase_24 AC 4 ms
7,792 KB
testcase_25 AC 4 ms
7,792 KB
testcase_26 AC 4 ms
7,792 KB
testcase_27 AC 4 ms
7,792 KB
testcase_28 AC 112 ms
15,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int>> G(200100);
pair<int,int> f(int x, int p){
	pair<int,int> ans = {0,1e18};
	bool k = true;
	for(int y:G[x])if(y != p){
		pair<int,int> a = f(y,x);
		ans.first = max(ans.first,a.second+1);
		ans.second = min(ans.second,a.first+1);
		k = false;
	}
	if(k) ans = {0,0};
	return ans;
}
signed main(){
    int N;
    cin>>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);
    }
    pair<int,int> a = f(0,-1);
    cout<<a.first<<endl;cout<<a.second<<endl;
}
0