Source:

PAT A1094 The Largest Generation (25 分)

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-digit ID's of his/her children. For the sake of simplicity, let us fix the root ID to be 01. 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的更多相关文章

  1. PAT1094:The Largest Generation

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. PAT 1094 The Largest Generation[bfs][一般]

    1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...

  3. pat1094. The Largest Generation (25)

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  4. PAT甲级——1094 The Largest Generation (树的遍历)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...

  5. 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 ...

  6. 1094 The Largest Generation ——PAT甲级真题

    1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...

  7. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  8. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  9. 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 ...

随机推荐

  1. 【LeetCode 6】Z 字形变换

    题目链接 [题解] 还想着模拟这个过程.然后发现只有行有用啊!... 那就建个rows大小的字符串数组存每行从左到右的字符就行啦.. 然后就是i从1变到n然后又变回1反复就好了. 最后把1..rows ...

  2. python实现收邮件判断模块poplib,email

    一.代码 # 输入邮件地址, 口令和POP3服务器地址: import datetime import email import poplib import email.policy from ema ...

  3. (转)websocket

    作者:Ovear链接:https://www.zhihu.com/question/20215561/answer/40316953来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  4. java.lang.Object错误

    java.lang.Object错误 项目遇到一个错误 因为构建路径不完整..... 主要是因为缺少JDK(java.lang.Object来自那里),或者是JDK错误. 右击项目-->属性-- ...

  5. HTML5 placeholder实际应用经验分享及拓展

    QQ邮箱登陆(http://mail.qq.com) 如下截图啦: 我在上面一个demo类似原理上做了下修改,制作了一个这样子交互效果的demo,希望对有兴趣的同行能帮上点忙,您可以狠狠地点击这里:透 ...

  6. Linux 下通过mail命令发送邮件

    mail -s "测试"  1968089885@foxmail.com 需要先配置smtp服务器

  7. Maven Optional & Exclusions使用区别

    Optional和Exclusions都是用来排除jar包依赖使用的,两者在使用上却是相反. Optional定义后,该依赖只能在本项目中传递,不会传递到引用该项目的父项目中,父项目需要主动引用该依赖 ...

  8. <Git>git学习

    1.安装 分布式版本控制:工作电脑保存完整的代码,中央服务器挂了也可以使用 集中式版本控制:中央服务器挂了就凉凉 sudo apt-get install git git安装 检测安装成功 git 2 ...

  9. Spring-boot整合Redis,遇到的问题

    1.通过set进redis中的数据,get不到 String cityKey ="city_"+id; ValueOperations<String,City> ope ...

  10. pytest的断言、跳过、运行的按需要处理

    def test_one(): assert 1==1 assert 1!=2 assert {'name':'linda','age':19}=={'name':'linda','age':190} ...