QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368714#3100. Meetings 2qwqer2330 0ms0kbC++141.7kb2024-03-27 15:41:142024-03-27 15:41:15

Judging History

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

  • [2024-03-27 15:41:15]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-03-27 15:41:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
vector<int> e[N],son[N];
bitset<N> vis;
int n,siz[N],mn=1e9,ms[N],dep[N],r,fa[N];
namespace LCA{
	int f[N][__lg(N)+2];
	void init(){
		for(int i=1;i<=n;i++) f[i][0]=fa[i];
		for(int i=1;i<=__lg(n)+1;i++) for(int j=1;j<=n;j++) f[j][i]=f[f[j][i-1]][i-1];
	}
	int lca(int x,int y){
		if(dep[x]<dep[y]) swap(x,y);
		for(int i=__lg(n)+1;i>=0;i--) if(dep[f[x][i]]>=dep[y]) x=f[x][i];
		if(x==y) return y;
		for(int i=__lg(n)+1;i>=0;i--) if(f[x][i]!=f[y][i]) x=f[x][i],y=f[y][i];
		return f[x][0];
	}
}
using LCA::lca;
int dis(int x,int y){return 1+dep[x]+dep[y]-2*dep[lca(x,y)];}
void dfs(int x,bool b=0){
	siz[x]=0,vis[x]=1;
	for(int i:e[x]){
		if(!vis[i]){
			if(b) fa[i]=x,son[x].push_back(i),dep[i]=dep[x]+1;
			dfs(i,b),siz[x]+=siz[i],ms[x]=max(ms[x],siz[i]);
		}
	}
	siz[x]++;
	ms[x]=max(ms[x],n-siz[x]);
	mn=min(mn,ms[x]);
}
int ans[N];
bool cmp(int x,int y){return siz[x]>siz[y];}
int main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int i,x,y;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x>>y;
		e[x].push_back(y),e[y].push_back(x);
	}
	dfs(1);
	for(i=1;i<=n;i++) if(ms[i]==mn) r=i;
	vis.reset(),dep[r]=1,dfs(r,1);
	LCA::init();
	vector<int> v(n);for(i=1;i<=n;i++) v[i-1]=i;
	sort(v.begin(),v.end(),cmp);
	int dx=r,dy=r,d=0;
	for(int i:v){
		int d1=dis(dx,i),d2=dis(dy,i);
		ans[siz[i]]=max(ans[siz[i]],max(d1,d2));
		if(d1>d&&d1>=d2) d=d1,dy=i;
		else if(d2>d) d=d2,dx=i;
	}
	for(i=1;i<=n;i++) if(i!=r) ans[siz[i]]=max(ans[siz[i]],dep[i]);
	for(i=n/2;i>=1;i--) ans[i]=max(ans[i],ans[i+1]);
	for(i=1;i<=n;i++){
		if(i&1) cout<<"1\n";
		else cout<<max(1,ans[i>>1])<<'\n';
	}
	return 0;
}

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%