結果
問題 | No.2532 Want Play More |
ユーザー | milanis48663220 |
提出日時 | 2023-11-03 22:26:09 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 128 ms / 2,000 ms |
コード長 | 1,977 bytes |
コンパイル時間 | 3,831 ms |
コンパイル使用メモリ | 119,376 KB |
実行使用メモリ | 47,276 KB |
最終ジャッジ日時 | 2023-11-03 22:26:16 |
合計ジャッジ時間 | 4,616 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
9,112 KB |
testcase_01 | AC | 115 ms
16,172 KB |
testcase_02 | AC | 113 ms
16,180 KB |
testcase_03 | AC | 106 ms
15,924 KB |
testcase_04 | AC | 104 ms
15,860 KB |
testcase_05 | AC | 128 ms
15,688 KB |
testcase_06 | AC | 86 ms
47,276 KB |
testcase_07 | AC | 5 ms
9,244 KB |
testcase_08 | AC | 7 ms
9,432 KB |
testcase_09 | AC | 6 ms
9,384 KB |
testcase_10 | AC | 44 ms
12,772 KB |
testcase_11 | AC | 43 ms
12,724 KB |
testcase_12 | AC | 85 ms
14,556 KB |
testcase_13 | AC | 55 ms
13,288 KB |
testcase_14 | AC | 18 ms
10,576 KB |
testcase_15 | AC | 96 ms
16,100 KB |
testcase_16 | AC | 78 ms
15,120 KB |
testcase_17 | AC | 5 ms
9,336 KB |
testcase_18 | AC | 56 ms
13,900 KB |
testcase_19 | AC | 85 ms
15,280 KB |
testcase_20 | AC | 4 ms
9,112 KB |
testcase_21 | AC | 3 ms
9,108 KB |
testcase_22 | AC | 3 ms
9,108 KB |
testcase_23 | AC | 3 ms
9,112 KB |
testcase_24 | AC | 4 ms
9,108 KB |
testcase_25 | AC | 3 ms
9,108 KB |
testcase_26 | AC | 3 ms
9,108 KB |
testcase_27 | AC | 3 ms
9,112 KB |
testcase_28 | AC | 46 ms
17,424 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector<int> g[200000]; int dp[200000][2]; // 0は最大化したい、1は最小化したい void dfs(int v, int par){ vector<int> children; for(int to: g[v]){ if(to == par){ continue; } children.push_back(to); } if(children.empty()){ return; } dp[v][1] = 1e9; for(int to: children){ dfs(to, v); chmax(dp[v][0], dp[to][1]+1); chmin(dp[v][1], dp[to][0]+1); } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; 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); } dfs(0, -1); cout << dp[0][0] << endl; cout << dp[0][1] << endl; }