QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#353839 | #8134. LCA Counting | SolitaryDream# | WA | 3ms | 15072kb | C++17 | 1.1kb | 2024-03-14 17:28:39 | 2024-03-14 17:28:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1e3+7;
int n;
vector<int> g[N];
priority_queue<int> s[N];
void dfs(int x)
{
for(auto v:g[x])
{
dfs(v);
if(s[v].size()>s[x].size())
s[x].swap(s[v]);
while(s[v].size())
{
int w=s[v].top();
s[v].pop();
s[x].push(w);
}
}
if(!s[x].size())
s[x].push(0);
else
{
if(s[x].size()>=2)
{
int u=s[x].top();
s[x].pop();
int v=s[x].top();
s[x].pop();
s[x].push(u+v+1);
}
}
}
int ans[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=2;i<=n;i++)
{
int x;
cin>>x;
g[x].push_back(i);
}
dfs(1);
int p=1;
while(s[1].size())
{
int x=s[1].top();
s[1].pop();
for(int j=1;j<=x;j++)
ans[p+j]=1;
p+=x+1;
}
for(int i=1;i<p;i++)
ans[i]+=ans[i-1],cout<<ans[i]+i<<" \n"[i+1==p];
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 15072kb
input:
7 1 1 2 4 2 2
output:
1 3 5 6
result:
ok 4 number(s): "1 3 5 6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 14636kb
input:
10 1 1 2 2 1 1 1 2 4
output:
1 3 5 6 7 8 9
result:
ok 7 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 14580kb
input:
10 1 2 2 4 5 6 1 2 4
output:
1 3 5 7 8
result:
ok 5 number(s): "1 3 5 7 8"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 14704kb
input:
10 1 2 3 3 3 5 6 4 9
output:
1 3 5
result:
wrong answer 3rd numbers differ - expected: '4', found: '5'