hdu 4707 bfs
来源:互联网 发布:办公网络 编辑:程序博客网 时间:2024/06/06 03:27
bfs基础算法水题
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include<queue>using namespace std;const int Max = 1e5+50;int dist[Max];vector<int> tree[Max];int N, D, T;void init(){for(int i = 0; i < Max-40; i ++){tree[i].clear();}memset(dist, 0, sizeof(dist));}int ans;void bfs(){int t = 0, dis = 0;queue<int> q;q.push(t);ans ++;while(!q.empty()){t = q.front();q.pop();if(dist[t] + 1 > D) continue;for(int i = 0; i < tree[t].size(); i ++){dist[tree[t][i]] = dist[t] + 1;ans ++;q.push(tree[t][i]);}}}int main(){int x, y;scanf("%d", &T);while(T --){init();scanf("%d%d", &N, &D);for(int i = 0; i < N-1; i ++){scanf("%d%d", &x, &y);tree[x].push_back(y);}ans = 0;bfs();printf("%d\n", N-ans);}return 0;}
0 0
- hdu 4707 bfs
- hdu 4707 Pet(dfs,bfs)
- HDU bfs
- HDU 4707 最后还是用了BFS。。。
- hdu 1175 bfs
- HDU 1072(BFS)
- HDU 1429(BFS )
- hdu 1026(BFS)
- HDU 4039 BFS
- hdu 1312 bfs
- hdu 1253 三维bfs
- hdu 1242 bfs
- BFS hdu 1072 Nightmare
- HDU 1072 Nightmare BFS
- bfs hdu 1026
- hdu-2757 BFS
- HDU-1495 BFS
- hdu 1401 bfs
- 【最大流】POJ 1145 PIGS
- html的表格
- ORACLE用户解锁的三种方法
- android 涂鸦与延时问题
- 关于GetDlgItem()出错问题
- hdu 4707 bfs
- android 中的 ViewPager+ Fragment
- 视频开发技术安全保障措施
- char 类型比较 基于vs2005 控制台
- Fragment Communicating with the Activity
- GDI+在固定位置(固定点)的地方绘制文本
- hdu 4942 Game on S♂play(线段树)
- C中的声明与定义
- 【拓扑排序】 HDOJ 1285 确定比赛名次