PAT1004. Counting Leaves
来源:互联网 发布:mysql不等于查询 编辑:程序博客网 时间:2024/06/09 20:15
一个dfs问题
#include<algorithm>#include<iostream>#include<vector>using namespace std;const int N=102;vector<int>son[N];int leaf[N],maxdeep;void dfs(int k,int deep){ maxdeep=max(maxdeep,deep); if(son[k].size()==0) leaf[deep]++; else{ for(auto &x:son[k]) dfs(x,deep+1); }}int main(){ int total,nonleaf; cin>>total>>nonleaf; while(nonleaf--){ int papa,cnt,k; cin>>papa>>cnt; while(cnt--){cin>>k;son[papa].push_back(k);} } dfs(1,0); for(int i=0;i<=maxdeep;++i){ if(i)cout<<' '; cout<<leaf[i]; } return 0;}
0 0
- 【PAT1004】Counting Leaves
- PAT1004. Counting Leaves (30)
- pat1004 Counting Leaves
- [搜索]PAT1004 Counting Leaves
- PAT1004. Counting Leaves
- 【PAT1004】Counting Leaves
- pat1004 Counting Leaves
- PAT1004. Counting Leaves bfs
- PAT1004 Counting Leaves
- Counting Leaves
- Counting Leaves
- pat 1004 Counting Leaves
- pat 1004 counting Leaves
- 1004. Counting Leaves
- 1004. Counting Leaves (30)
- 1004. Counting Leaves
- PAT_1004: Counting Leaves
- PAT 1004 Counting Leaves
- C#软件开发实例.私人订制自己的屏幕截图工具(十)在截图中包含鼠标指针形状
- 初学Android—关于findViewById函数
- 廊道建模
- 如何判断Linux是32位还是64位
- sscanf函数学习
- PAT1004. Counting Leaves
- PS CS4 改变文字字体时弹出“ 无法完成请求 因为程序错误”信息的解决方法
- POJ 2486 Apple Tree(树形dp)
- Android Fragment完全解析,关于碎片你所需知道的一切
- Android学习之 监听网络连接状态的改变
- single num--唯一一个只出现一次 的数
- CSS3下不一样的阴影、背景和圆角边框样式
- 哈希表对字符串的高效处理2:在一个字符中删除第二个字符出现过的所有字符
- 一种使用QThread线程的新方法QObject::moveToThread