求助,十分感谢
查看原帖
求助,十分感谢
826770
Xffishr楼主2023/10/27 19:35

为什么样例过了,但是全爆0了

#include<bits/stdc++.h>
using namespace std;
int n,d;
int w[99999],v[99999],h[99999],nxt[99999],tot;
int ans=0;
int book[99999];
//
void add(int x,int y,int z){
	v[tot]=y;
	w[tot]=z;
	nxt[tot]=h[x];
	h[x]=tot;
	tot++;
	return;
}
//
void func(int x,int step){
	if(step<=d)ans++;
		for(int i=h[x];i;i=nxt[i]){
			if(book[v[x]]==0){
				book[v[x]]=1;
				func(v[x],step+1);
			}
	
	} 
	
	return;
}
int main(){
	cin>>n>>d;
	for(int i=1;i<=n-1;i++){
		int a,b;
		cin>>a>>b;
		add(a,b,1);
		add(b,a,1);
	}
	func(1,0);
	cout<<ans;
	return 0;
}

2023/10/27 19:35
加载中...