PAT_A1094#The Largest Generation
Source:
Description:
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.
Input Specification:
Each input file contains one test case. Each case starts with two positive integers N (<) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to N), and M (<) which is the number of family members who have children. Then M lines follow, each contains the information of a family member in the following format:
ID K ID[1] ID[2] ... ID[K]
where
ID
is a two-digit number representing a family member,K
(>) is the number of his/her children, followed by a sequence of two-digitID
's of his/her children. For the sake of simplicity, let us fix the rootID
to be01
. All the numbers in a line are separated by a space.
Output Specification:
For each test case, print in one line the largest population number and the level of the corresponding generation. It is assumed that such a generation is unique, and the root level is defined to be 1.
Sample Input:
23 13
21 1 23
01 4 03 02 04 05
03 3 06 07 08
06 2 12 13
13 1 21
08 2 15 16
02 2 09 10
11 2 19 20
17 1 22
05 1 11
07 1 14
09 1 17
10 1 18
Sample Output:
9 4
Keys:
Code:
/*
time: 2019-08-24 15:25:08
problem: PAT_A1094#The Largest Generation
AC: 18:52 题目大意:
求树中结点个数最多的层次及其结点个数 基本思路:
遍历并统计各层次人数即可
*/
#include<cstdio>
#include<vector>
using namespace std;
const int M=1e3;
vector<int> tree[M];
int scale[M]={},largest=,generation; void Travel(int root, int layer)
{
scale[layer]++;
if(scale[layer] > largest)
{
largest = scale[layer];
generation = layer;
}
for(int i=; i<tree[root].size(); i++)
Travel(tree[root][i],layer+);
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,m,id,k,kid;
scanf("%d%d", &n,&m);
for(int i=; i<m; i++)
{
scanf("%d%d", &id,&k);
for(int j=; j<k; j++)
{
scanf("%d", &kid);
tree[id].push_back(kid);
}
}
Travel(,);
printf("%d %d", largest,generation); return ;
}
PAT_A1094#The Largest Generation的更多相关文章
- PAT1094:The Largest Generation
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT 1094 The Largest Generation[bfs][一般]
1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...
- pat1094. The Largest Generation (25)
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- PAT (Advanced Level) Practise - 1094. The Largest Generation (25)
http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...
- 1094 The Largest Generation ——PAT甲级真题
1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...
- PTA甲级1094 The Largest Generation (25分)
PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...
- 1094. The Largest Generation (25)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- PAT A1094 The Largest Generation (25 分)——树的bfs遍历
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
随机推荐
- RF中滚动条的操作方法小结
滚动条分为俩种,一:主页面中的滚动条.二:页面中的子页面的滚动条. 每种滚动条有都分为上下滑动与左右滑动. 下面分别介绍: 一:主页面的滚动条上下滑动: execute javascript ...
- MySql精简
安装的是免安装版MySql 由于MySql是开源的,故下载的时候源码也会包含,如果单纯只是使用其功能,则可以将这些文件删除为MySql减肥 可以删除的文件有如下: 1.mysql-test 文件夹: ...
- flutter 小知识
隐藏控件,占空间 new Offstage( offstage: true, //这里控制 child: Container(color: Colors.blue,height: 100.0,), ) ...
- 【SVN】提交报错:×××文件is not under version control
解决方法:1.删除出错的文件,然后在出错文件所在文件夹执行还原操作 2.VS中可将文件先排除在项目外,再包含在项目内,即可正常提交
- 导入安全证书到jdk
一:.导入证书 1.打开doc窗口,打开cmd,执行命令: keytool -import -file f:\ca.crt -keystore "%JAVA_HOME%\jre\lib\se ...
- HDU 6697 Closest Pair of Segments (计算几何 暴力)
2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...
- Collection map
HashMap 的工作原理及代码实现 底层数组+链表实现,可以存储null键和null值,线程不安全 初始size为16,扩容:newsize = oldsize*2,size一定为2的n次幂 扩容针 ...
- 自从阿里买了Flink母公司以后,你不懂Flink就out了!
个免费报名权限 Ps:小助理手动给大家发送资料,精力有限,仅限前100名免费领取,这份资料对于想要提升大数据技能进阶的小伙伴来说,将会是一份不可或缺的宝贵资料. 特别感谢飞总的部分原创支持!
- Java Selenium起步
先将录制的脚本导出来,转成java的格式 在Eclipse中编辑并运行test 2.1 新建一个Java project: File-New-Java Project 2.2 在上一步 ...
- easyui datagrid 绑定json对象属性的属性
今天用easyui 的datagrid绑定数据时,后台提供的数据是实体类类型的,其中有一个实体类A的属性b是另一个实体类B类型的,而前台需要显示b的属性c,这下就悲剧了,前台没法直接绑定了,后来脑筋一 ...