QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#560395 | #3100. Meetings 2 | goj_bot1 | 0 | 0ms | 0kb | C++14 | 2.3kb | 2024-09-12 15:30:23 | 2024-09-12 15:30:23 |
answer
#include<bits/stdc++.h>
#define N 200010
#define Pii pair<int,int>
#define Fi first
#define Se second
using namespace std;
inline bool Isdigit(char c){return c>='0'&&c<='9';}
template<typename T>inline T read(){
T x=0;
char c=getchar();
while(!Isdigit(c))c=getchar();
while(Isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
return x;
}
vector<Pii> g[N];
priority_queue<Pii,vector<Pii>,greater<Pii> > q;
int n,u,v,cnt,Res[N],vis[N],d[N],head[N],dep[N],siz[N],To[N<<1],Nxt[N<<1],f[N][20];
inline void add(int from,int to){
To[++cnt]=to;
Nxt[cnt]=head[from];
head[from]=cnt;
}
void dfs(int now,int fa){
f[now][0]=fa;
dep[now]=dep[fa]+1;
for(int i=1;i<=18;i++)
f[now][i]=f[f[now][i-1]][i-1];
for(int i=head[now];i;i=Nxt[i])
if(To[i]^fa)dfs(To[i],now);
}
inline int get_Lca(int x,int y){
if(dep[x]<dep[y])
swap(x,y);
for(int i=18;i>=0;i--)
if(dep[f[x][i]]>=dep[y])
x=f[x][i];
if(x==y)return x;
for(int i=18;i>=0;i--)
if(f[x][i]^f[y][i])
x=f[x][i],y=f[y][i];
return f[x][0];
}
inline int get_Dis(int x,int y){
return dep[x]+dep[y]-(dep[get_Lca(x,y)]<<1);
}
int main(){
n=read<int>();
for(int i=1;i<n;i++){
u=read<int>(),v=read<int>();
add(u,v),add(v,u);
d[u]++,d[v]++;
}
dfs(1,0);
for(int i=1;i<=n;i++){
siz[i]=1;
if(d[i]==1)
q.emplace(1,i);
}
for(int i=1;i<=(n>>1)+1;i++)
while(q.size()&&q.top().Fi<i){
int now=q.top().Se;
q.pop();
vis[now]=1;
for(int j=head[now];j;j=Nxt[j]){
if(vis[To[j]])continue;
g[i].emplace_back(now,To[j]);
siz[To[j]]+=siz[now];
if((--d[To[j]])<=1)
q.emplace(siz[To[j]],To[j]);
}
}
int x,y,Len=1;
x=y=q.top().Se;
for(int i=(n>>1)+1;i>=1;i--){
Res[i]=Len;
for(auto [a,b]:g[i]){
int La=get_Dis(x,y);
int Lb=get_Dis(x,a);
int Lc=get_Dis(y,a);
if(Lb>La&&Lb>Lc)y=a;
else if(Lc>La)x=a;
Len=max(max(La,Lb),Lc)+1;
}
}
for(int i=1;i<=n;i++)
if(i&1)puts("1");
else printf("%d\n",Res[i>>1]);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%