結果
| 問題 | No.3206 う し た ウ ニ 木 あ く ん 笑 |
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2025-07-18 21:40:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 426 ms / 3,000 ms |
| コード長 | 2,476 bytes |
| 記録 | |
| コンパイル時間 | 4,076 ms |
| コンパイル使用メモリ | 264,328 KB |
| 実行使用メモリ | 89,128 KB |
| 最終ジャッジ日時 | 2025-07-18 21:40:45 |
| 合計ジャッジ時間 | 10,345 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 |
ソースコード
#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 1000000000000000001LL
vector<vector<int>> G;
template <class Ss, Ss (*op0)(Ss, Ss), Ss (*e)(), class Sv, Ss (*op1)(Sv, Ss), class Se, Ss (*op2)(Se, Ss)>
struct rerooting{
int n;
vector<vector<int>> to;
vector<vector<Se>> edge;
vector<Ss> subtree,answer;
vector<Sv> vertex;
rerooting(int _n){
n = _n;
to.resize(n);
edge.resize(n);
subtree.resize(n,e());
answer.resize(n,e());
vertex.resize(n);
}
rerooting(vector<Sv> v){
n = v.size();
to.resize(n);
edge.resize(n);
subtree.resize(n,e());
answer.resize(n,e());
vertex = v;
}
void add_directed_edge(int u,int v,Se x){
to[u].push_back(v);
edge[u].push_back(x);
}
void add_edge(int u,int v,Se x){
add_directed_edge(u,v,x);
add_directed_edge(v,u,x);
}
void solve(){
dfs(0,-1);
//cout<<'a'<<endl;
redfs(0,-1,e());
}
void dfs(int cur,int par){
Ss temp = e();
for(int i=0;i<to[cur].size();i++){
int nxt = to[cur][i];
if(nxt==par)continue;
dfs(nxt,cur);
temp = op0(temp, op2(edge[cur][i], subtree[nxt]));
}
subtree[cur] = op1(vertex[cur], temp);
}
void redfs(int cur, int par, Ss ps){
vector<Ss> P(to[cur].size()+1,e());
rep(i,to[cur].size()){
int nxt = to[cur][i];
if(nxt!=par)P[i+1] = op2(edge[cur][i], subtree[nxt]);
else P[i+1] = op2(edge[cur][i], ps);
}
vector<Ss> S(P.rbegin(),P.rend()-1);
S.insert(S.begin(),e());
rep(i,to[cur].size()){
G[cur].push_back(P[i+1]);
P[i+1] = op0(P[i], P[i+1]);
S[i+1] = op0(S[i+1], S[i]);
}
answer[cur] = op1(vertex[cur], P.back());
for(int i=0;i<to[cur].size();i++){
int nxt = to[cur][i];
if(nxt!=par){
redfs(nxt,cur,op1(vertex[cur], op0(P[i],S[to[cur].size()-1-i])));
}
}
}
};
int op0(int a,int b){
return max(a,b);
}
int e(){
return 0;
}
int op1(long long a,int b){
return b;
}
int op2(long long a,int b){
return b+1;
}
int main(){
int n;
cin>>n;
rerooting<int, op0, e, long long, op1,long long, op2> R(n);
rep(i,n-1){
int a,b;
cin>>a>>b;
a--,b--;
R.add_edge(a,b,1);
}
G.resize(n);
R.solve();
int ans = 0;
rep(i,n){
sort(G[i].rbegin(),G[i].rend());
rep(j,G[i].size()){
ans = max(ans,1 + G[i][j] * (j+1));
// cout<<G[i][j]<<' ';
}
//cout<<endl;
}
cout<<ans<<endl;
return 0;
}
沙耶花