QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#331855 | #3100. Meetings 2 | xie_lzh | 0 | 5ms | 22008kb | C++14 | 1.9kb | 2024-02-18 20:36:51 | 2024-02-18 20:36:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,t,siz[N],maxp[N],rt;
bool vis[N];
vector<int> to[N];
int anssiz[N],nanssiz[N],ans[N];
void findrt(int x,int all,int f)
{
siz[x]=1; maxp[x]=0;
for(int v:to[x])
{
if(v==f||vis[v]) continue;
findrt(v,all,x);
siz[x]+=siz[v];
maxp[x]=max(maxp[x],siz[v]);
}
maxp[x]=max(maxp[x],all-siz[x]);
if(rt==0||maxp[x]<maxp[rt]) rt=x;
}
void work(int x,int f,int ndep)
{
nanssiz[siz[x]]=max(nanssiz[siz[x]],ndep);
for(int v:to[x])
{
if(vis[v]||v==f) continue;
work(v,x,ndep+1);
}
}
void getsiz(int x,int f)
{
siz[x]=1;
for(int v:to[x])
{
if(vis[v]||v==f) continue;
getsiz(v,x); siz[x]+=siz[v];
}
}
void calc(int x)
{
for(int v:to[x])
{
if(vis[v]) continue;
work(v,x,1);
for(int i=siz[v];i>=1;i--)
{
nanssiz[i]=max(nanssiz[i],nanssiz[i+1]);
if(nanssiz[i]==0) continue;
if(anssiz[i]) ans[i]=max(ans[i],anssiz[i]+nanssiz[i]+1);
anssiz[i]=max(anssiz[i],nanssiz[i]);
}
for(int i=1;i<=siz[v];i++)
nanssiz[i]=0;
int ans2=min(siz[v],siz[x]-siz[v]);
for(int i=ans2;i>=1;i--) ans[i]=max(ans[i],2);
}
for(int i=1;i<=siz[x];i++) anssiz[i]=0;
}
void solve(int x)
{
rt=0;
findrt(x,siz[x],0); getsiz(rt,0); vis[rt]=1;
calc(rt);
for(int v:to[rt]) if(!vis[v]) solve(v);
}
void solve()
{
cin>>n;
for(int u,v,i=1;i<n;i++)
{
cin>>u>>v;
to[u].push_back(v);
to[v].push_back(u);
}
for(int i=1;i<=n;i++) ans[i]=1;
siz[1]=n; solve(1);
for(int i=1;i<=n;i++)
if(i&1) cout<<"1\n";
else cout<<ans[i/2]<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// cin>>t;
t=1;
while(t--) solve();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 5ms
memory: 22008kb
input:
1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 2ms
memory: 17996kb
input:
2 2 1
output:
1 2
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 20020kb
input:
3 1 3 3 2
output:
1 3 1
result:
ok 3 lines
Test #4:
score: -4
Wrong Answer
time: 0ms
memory: 20020kb
input:
14 12 14 12 9 14 2 12 6 12 7 6 4 3 4 1 4 12 8 13 1 10 12 11 6 6 5
output:
1 7 1 5 1 2 1 2 1 2 1 2 1 2
result:
wrong answer 6th lines differ - expected: '3', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%