QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#807117 | #7961. 一棵树 | dxbt | Compile Error | / | / | C++14 | 1.2kb | 2024-12-09 19:02:19 | 2024-12-09 19:02:20 |
Judging History
This is the latest submission verdict.
- [2024-12-09 19:02:20]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-12-09 19:02:19]
- Submitted
answer
#include<bits/stdc++.h>
#define F(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
using namespace std;
typedef long long ll;
constexpr int N=5e5;
priority_queue<ll,vector<ll>,less<ll> > q[N+9];
int n,k;vector<int> E[N+9];int tag[N+9];
int gen;
int dfs1(int x,int fa)
{
int sz=1,mx=0;
for(auto u:E[x])
if(u!=fa)
{
int t=dfs1(u,x);
sz+=t;
mx=max(mx,t);
}
if(sz>n/2&&mx<=n/2) gen=x;
return sz;
}
void dfs(int x,int fa)
{
q[x].push(0);
for(auto u:E[x])
{
if(u==fa)continue;
dfs(u,x);
if(q[u].size()>q[x].size())swap(q[x],q[u]),swap(tag[x],tag[u]);
while(!q[u].empty())q[x].push(q[u].top()+tag[u]-tag[x]),q[u].pop();
}
if(fa)
{
while(q[x].size()>(k+1)/2) q[x].pop();
tag[x]-=2;
if(k&1&&q[x].size()==(k+1)/2)
{
ll p=q[x].top();
q[x].pop();
q[x].push(p+2);
}
}
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
cin>>n>>k;
F(i,1,n-1)
{
int u,v;
cin>>u>>v;
E[u].ep(v);
E[v].ep(u);
}
dfs1(1,0);
dfs(gen,0);
ll ans=1ll*(n-1)*k;
while(q[gen].size()>k)q[gen].pop();
F(i,1,k)
{
ans+=q[gen].top()+tag[gen];
q[gen].pop();
}
cout<<ans<<'\n';
return 0;
}
详细
answer.code: In function ‘int main()’: answer.code:52:22: error: ‘class std::vector<int>’ has no member named ‘ep’ 52 | E[u].ep(v); | ^~ answer.code:53:22: error: ‘class std::vector<int>’ has no member named ‘ep’ 53 | E[v].ep(u); | ^~