結果
問題 |
No.3206 う し た ウ ニ 木 あ く ん 笑
|
ユーザー |
![]() |
提出日時 | 2025-07-18 21:40:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,947 bytes |
コンパイル時間 | 1,424 ms |
コンパイル使用メモリ | 132,360 KB |
実行使用メモリ | 61,696 KB |
最終ジャッジ日時 | 2025-07-18 21:40:49 |
合計ジャッジ時間 | 4,702 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 13 WA * 17 |
ソースコード
#include <iostream> #include <iomanip> #include <cassert> #include <vector> #include <algorithm> #include <utility> #include <numeric> #include <tuple> #include <ranges> namespace ranges = std::ranges; namespace views = std::views; // #include "Src/Number/IntegerDivision.hpp" // #include "Src/Utility/BinarySearch.hpp" // #include "Src/Sequence/CompressedSequence.hpp" // #include "Src/Sequence/RunLengthEncoding.hpp" // #include "Src/Algebra/Group/AdditiveGroup.hpp" // #include "Src/DataStructure/FenwickTree/FenwickTree.hpp" // #include "Src/DataStructure/SegmentTree/SegmentTree.hpp" // #include "Src/DataStructure/DisjointSetUnion/DisjointSetUnion.hpp" // using namespace zawa; // #include "atcoder/modint" // using mint = atcoder::modint998244353; int N; std::vector<int> g[200020]; void dfs(int v, int p, std::vector<int>& dep, int d) { dep[v] = d; for (int x : g[v]) if (x != p) dfs(x, v, dep, d + 1); } int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N; for (int i = 0 ; i < N - 1 ; i++) { int u, v; std::cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } std::vector<int> dep(N); dfs(0, -1, dep, 0); int ans = 0; auto rec = [&](auto rec, int v, int p) -> int { std::vector<int> can; can.reserve(g[v].size()); int take = 1; for (int x : g[v]) { if (x == p) can.push_back(dep[v]); else { const int ch = rec(rec, x, v); take = std::max(take, ch + 1); can.push_back(ch); } } ranges::sort(can, std::greater<int>{}); for (int i = 0 ; i < std::ssize(can) ; i++) { const int val = can[i] * (i + 1) + 1; ans = std::max(ans, val); } return take; }; rec(rec, 0, -1); std::cout << ans << '\n'; }