hdu 4707 dfs+前向星
来源:互联网 发布:不可思议迷宫 知乎 编辑:程序博客网 时间:2024/06/05 16:34
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;struct node{ int to,next;}A[100010];int list[100010];int tot,n,d;int deal(int a,int b){ A[++tot].to=b; A[tot].next=list[a]; list[a]=tot; return 0; }int dfs(int a,int t){ if(t>=d) return 1; int i,sum=1; for(i=list[a];i>=0;i=A[i].next) { int k=A[i].to; sum+=dfs(k,t+1); } return sum;}int main(){ int T,i,j,a,b; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&d); tot=1; memset(list,-1,sizeof(list)); for(i=1;i<n;i++) { scanf("%d%d",&a,&b); deal(a,b); } int k=dfs(0,0); printf("%d\n",n-k); } return 0;}
0 0
- hdu 4707 dfs+前向星
- dfs+链式前向星
- hdu5438 dfs+拓扑排序+前向星
- 链式前向星+b/dfs
- ZOJ 1708||hdu 1035 Robot Motion (链式前向星,dfs)
- hdu 2647【反向拓扑+前向星】
- DFS&BFS(链式前向星实现)
- DFS和BFS链式前向星的实现
- 哗啦啦村的扩建(DFS+链式前向星)
- hdu 1874 单源最短路径spfa+链式前向星
- hdu 2647 Rewaed(拓扑排序+链式前向星)
- HDU 1535 Invitation Cards 【SPFA + 链式前向星】
- hdu 4463 Outlets(最小生成树,kruskal,前向星)
- HDU 2647 Reward (拓扑排序 + 链式前向星 )
- [HDU 2544] 最短路 spfa写法 + 链式前向星
- HDU 2544 SPFA+前向星模板题
- 前向星,链式前向星
- 建图方式一 之 ”前向星“ BFS&&DFS 简单应用
- OC - 单例模式
- eclipse下安装pydev,google app engine 插件无法显示设置的问题
- Q1.7 set Matrix zeroes
- tinyhttpd-0.1.0和win移植版
- Allegro 导出 SMT 元件位置坐标
- hdu 4707 dfs+前向星
- 获取网卡MAC、硬盘序列号、CPU_ID、BIOS编号
- python中的魔法参数:*args和**kwargs
- 修改tomcat端口和启动时间45秒和编码
- MySQL中的表中字段增删改
- 黑马程序员——入学Blog04----OC的构造方法
- java EE介绍
- 一站式学习Wireshark
- java基础——线程