40pts奇特思路求hack/求条
查看原帖
40pts奇特思路求hack/求条
827873
abc1856896楼主2024/10/31 17:02
#include<bits/stdc++.h>
int head[3000005],cnt,maxx=0;
struct data{
	int to;
	int next;
};
data edge[3000005];
void add_edge(int from,int to){
	cnt++;
	edge[cnt].to=to;
	edge[cnt].next=head[from];
	head[from]=cnt;
}
//addedge(from,to,w)
int n,dp[3000005];
void dfs(int u,int father) {
	int sum=0;
	for(int i=head[u];i;i=edge[i].next) {
		int v=edge[i].to;
		if(v!=father) {
			sum++;
			dfs(v,u);
		}	
	}
	maxx=std::max(maxx,sum);
}
/*
*/
signed main(){
	std::cin>>n;
	for(int i=1;i<n;i++) {
		int u,v;
		std::cin>>u>>v;
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,1);
	std::cout<<maxx;
	return 0;
}
2024/10/31 17:02
加载中...