結果
| 問題 | No.3206 う し た ウ ニ 木 あ く ん 笑 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-18 21:37:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,855 bytes |
| コンパイル時間 | 2,293 ms |
| コンパイル使用メモリ | 171,440 KB |
| 実行使用メモリ | 68,840 KB |
| 最終ジャッジ日時 | 2025-07-18 21:37:18 |
| 合計ジャッジ時間 | 5,683 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 20 |
ソースコード
#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 cnt = 1;
if(v == 0) cnt = 0;
int mn = dp2[v];
if(v == 0) mn = 1e9;
for(int to : T[v]) if(to != p){
cnt++;
mn = min(mn, dp1[to]);
}
ans = max(ans, 1+cnt*mn);
//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);
cout << ans << '\n';
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int T=1;
//cin >> T;
while(T--) solve();
}