PAT a1004题解
来源:互联网 发布:凡科建站怎么监测数据 编辑:程序博客网 时间:2024/05/17 22:33
#include <cstdio>#include <queue>#include <vector>using namespace std;const int N = 105;vector<int> G[N];int leaf[N] = {0};int h[N] = {0};int max_h = 0;void BFS(){queue<int> Q;Q.push(1);while(!Q.empty()){int id = Q.front();Q.pop();max_h = max(max_h, h[id]);if(G[id].size() == 0){leaf[h[id]]++;}for(int i = 0; i < G[id].size(); i++){h[G[id][i]] = h[id] + 1;Q.push(G[id][i]);}}}int main(){int n, m;scanf("%d%d", &n, &m);for(int i = 0; i < m; i++){int parent, k, child;scanf("%d%d", &parent, &k);for(int j = 0; j < k; j++){scanf("%d", &child);G[parent].push_back(child);}}h[1] = 1;BFS();for(int i= 1; i <= max_h; i++){if(i == 1) printf("%d", leaf[i]);else printf(" %d", leaf[i]);}return 0;}
阅读全文
1 0
- PAT a1004题解
- PAT A1004
- PAT-A1004
- pat a1004(暂缺)
- PAT A1004 Counting Leaves(30)
- PAT A1004. Counting Leaves (30)
- PAT甲级练习题A1004. Counting Leaves
- PAT 1001-1010 题解
- PAT 1011-1020 题解
- PAT 1021-1030 题解
- PAT 1031-1040 题解
- PAT 1041-1050 题解
- PAT 1051-1060 题解
- PAT(basic level)题解
- PAT乙级题解
- PAT题解目录
- PAT甲级题解目录
- PAT乙级题解目录
- Dreamweaver 8安装
- TensorFlow学习笔记(二)MNIST入门
- 关于KEIL5打开KEIL4工程之后工程后缀变为uvprojx
- Git(分布式版本控制系统)——操作篇(二)
- SQL 快速参考
- PAT a1004题解
- js domcontentloader
- sklearn学习之贝叶斯分类
- mysql安装--windows下
- 关于mono dll和native dll在unity使用
- GreenPlum之数组合并取交集及行变列、列变行函数
- zxing二维码不可以多次扫描
- 三分法求函数最大值(求导求极值)
- 713总结