QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#228609#3869. Gastronomic Eventucup-team1004WA 2ms11412kbC++14852b2023-10-28 13:47:252023-10-28 13:47:25

Judging History

你现在查看的是最新测评结果

  • [2023-10-28 13:47:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11412kb
  • [2023-10-28 13:47:25]
  • 提交

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'