QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#228609 | #3869. Gastronomic Event | ucup-team1004 | WA | 2ms | 11412kb | C++14 | 852b | 2023-10-28 13:47:25 | 2023-10-28 13:47:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;using ll=long long;const int N=2.5e5+10;
int n,rt,siz[N],mx[N],cnt[N];ll ans;vector<int>A[N];bitset<N>f;
void add(int u,int v){A[u].push_back(v);A[v].push_back(u);}
void dfs1(int u,int fa=0){siz[u]=1;for(int v:A[u])if(v^fa)dfs1(v,u),mx[u]=max(mx[u],siz[v]),siz[u]+=siz[v];}
void dfs2(int u,int fa=0,int d=0){ans+=d;siz[u]=1;for(int v:A[u])if(v^fa)dfs2(v,u,d+1),siz[u]+=siz[v];}
int main(){
scanf("%d",&n);for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),add(u,v);dfs1(1);
rt=1;for(int i=1;i<=n;i++)mx[i]=max(mx[i],n-siz[i]),rt=mx[i]<mx[rt]?i:rt;
dfs2(rt);for(int v:A[rt])cnt[siz[v]]++;for(int i=1;i<=n;i++)for(;cnt[i]>2;cnt[i]-=2)cnt[i*2]++;
f[0]=1;for(int i=1;i<=n;i++)for(int j=1;j<=cnt[i];j++)f|=f<<i;
for(int i=(n-1)/2;~i;i--)if(f[i]){ans+=1ll*i*(n-1-i);break;}cout<<n-1<<' '<<ans;return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11412kb
input:
5 1 2 2 2
output:
4 22
result:
wrong answer 1st lines differ - expected: '13', found: '4 22'