結果
問題 |
No.3206 う し た ウ ニ 木 あ く ん 笑
|
ユーザー |
|
提出日時 | 2025-07-18 21:33:46 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,772 bytes |
コンパイル時間 | 1,716 ms |
コンパイル使用メモリ | 173,308 KB |
実行使用メモリ | 68,860 KB |
最終ジャッジ日時 | 2025-07-18 21:33:54 |
合計ジャッジ時間 | 5,411 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 1 |
other | AC * 2 WA * 28 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; void solve(){ int n; cin >> n; vector<vector<int>> T(n); for(int i=0; i<n-1; i++){ int u, v; cin >> u >> v; u--; v--; T[u].push_back(v); T[v].push_back(u); } vector<int> dp1(n, 1); function<void(int, int)> dfs1 = [&](int v, int p) { for(int to : T[v]) if(to != p){ dfs1(to, v); dp1[v] = max(dp1[v], dp1[to]+1); } }; dfs1(0, -1); int ans = 0; vector<int> dp2(n, 0); function<void(int, int)> dfs2 = [&](int v, int p) { { int sa = dp2[v] + 1; for(int to : T[v]) if(to != p) sa += dp1[to]; ans = max(ans, sa); //cout << v << ": " << sa << '\n'; } multiset<int> mst; mst.insert(dp2[v]); for(int to : T[v]) if(to != p) mst.insert(dp1[to]); for(int to : T[v]) if(to != p){ mst.erase(mst.find(dp1[to])); dp2[to] = 1 + (mst.empty() ? 0 : *mst.rbegin()); mst.insert(dp1[to]); } for(int to : T[v]) if(to != p) dfs2(to, v); }; dfs2(0, -1); // for(int i=0; i<n; i++) cout << dp1[i] << ' ' << dp2[i] << '\n'; cout << ans << '\n'; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }