結果
問題 | No.2532 Want Play More |
ユーザー | Kude |
提出日時 | 2023-11-03 22:43:07 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 157 ms / 2,000 ms |
コード長 | 1,624 bytes |
コンパイル時間 | 3,592 ms |
コンパイル使用メモリ | 275,760 KB |
実行使用メモリ | 36,080 KB |
最終ジャッジ日時 | 2023-11-03 22:43:15 |
合計ジャッジ時間 | 6,107 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 127 ms
14,168 KB |
testcase_02 | AC | 125 ms
14,168 KB |
testcase_03 | AC | 157 ms
13,904 KB |
testcase_04 | AC | 123 ms
13,640 KB |
testcase_05 | AC | 119 ms
13,376 KB |
testcase_06 | AC | 86 ms
36,080 KB |
testcase_07 | AC | 3 ms
4,348 KB |
testcase_08 | AC | 5 ms
4,348 KB |
testcase_09 | AC | 4 ms
4,348 KB |
testcase_10 | AC | 44 ms
8,428 KB |
testcase_11 | AC | 42 ms
8,164 KB |
testcase_12 | AC | 79 ms
11,528 KB |
testcase_13 | AC | 52 ms
9,220 KB |
testcase_14 | AC | 17 ms
5,260 KB |
testcase_15 | AC | 109 ms
14,168 KB |
testcase_16 | AC | 91 ms
12,320 KB |
testcase_17 | AC | 4 ms
4,348 KB |
testcase_18 | AC | 62 ms
10,276 KB |
testcase_19 | AC | 89 ms
12,584 KB |
testcase_20 | AC | 4 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 | 2 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 | 54 ms
16,976 KB |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VVI to(n); rep(_, n - 1) { int u, v; cin >> u >> v; u--, v--; to[u].emplace_back(v); to[v].emplace_back(u); } constexpr int INF = 1001001001; auto dfs = [&](auto&& self, int u, int p, int d) -> P { vector<P> res; for (int v : to[u]) if (v != p) { auto r = self(self, v, u, d + 1); res.emplace_back(r); } if (res.empty()) return {0, 0}; if (d % 2 == 0) { P ans{-INF, INF}; for (auto [x, y] : res) { chmax(ans.first, x + 1); chmin(ans.second, y + 1); } return ans; } else { P ans{INF, -INF}; for (auto [x, y] : res) { chmin(ans.first, x + 1); chmax(ans.second, y + 1); } return ans; } }; auto [x, y] = dfs(dfs, 0, -1, 0); cout << x << '\n' << y << '\n'; }