蒟蒻求助
查看原帖
蒟蒻求助
1161545
_XSOI_楼主2023/12/14 19:11

bfs 0 pts\text{bfs 0 pts}。

不知道哪里错了,照着题解检查了也看不出来。

悬关。

#include <iostream>
#include <vector>
using namespace std;
const int MAXX = 100011;
bool vis[MAXX];
vector <int> g[MAXX];
int sum;
int n,d;
void dfs(int now,int step) {
	vis[now] = 1;
	if(step == d) {
		return;
	}
	for(int i = 0; i < g[now].size(); i ++) {
		if(vis[g[now][i]] != 0) {
			dfs(g[now][i],step+1);
			sum ++;
		}
	}
}
int main() {
	cin>>n>>d;
	for(int i = 1; i <= n; i ++) {
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1,0);
	cout<<sum;
	return 0;
}
2023/12/14 19:11
加载中...