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. opencv打开摄像头并新建窗口显示

    几个程序使用的基本函数如下: ******************************************************************* cvCreateCameraCap ...

  2. 22、继续javascript,左边选中的跳到右边

    1. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title& ...

  3. HBase 永久RIT(Region-In-Transition)问题

    HBase 永久RIT(Region-In-Transition)问题:异常关机导致HBase表损坏和丢失,大量Regions 处于Offline状态,无法上线. 问题1:启动HBase时,HBase ...

  4. 用EditText控件的属性inputType

    android:inputType参数类型说明 android:inputType="none"--输入普通字符 android:inputType="text" ...

  5. 4-vim-工作模式-01-职责以及切换模式

    vi 有三种工作模式 1.命令模式 打开文件首先进入命令模式,是使用vi的入口. 通过命令对文件进行常规的编辑操作,例如:定位-翻页-复制-粘贴-删除等. 在其他图形编辑器下,通过快捷键或鼠标实现的操 ...

  6. uoj#244. 【UER #7】短路

    题目 orz myy 这个矩形对称的性质非常优美,所以我们只需要考虑一个\(\frac{1}{4}\)的矩阵,即一个倒三角形 现在我们要求的是从\((1,1)\)到三角形对边上每个点的最短路,不难发现 ...

  7. AForge.Video.FFMPEG库几个注意事项

    同事开发过程中,读写摄像头遇到的问题. 在录制和取消反复切换就会报内存越界的错误,这是由于open和close没有线程同步造成的. 参考如下文章得到了解决思路,最后Open和Close用一个静态锁解决 ...

  8. linux inode节点数报警处理

    1.问题描述 zabbix 收到一台服务器的Free inodes is less than 20% on volume / 报警 登陆服务器查看 产生原因:一般就是小文件比较多,占用大量的inode ...

  9. 面对对象(JS)

    面对对象的三大特征:封闭.继承.多态 七大基本原则:    1.单一职责    2.开闭原则    3.里氏替换    4.依赖倒置    5.接口隔离    6.迪米特法则    7.01组合/聚合 ...

  10. 8.Struts2拦截器

    1. 拦截器的概述 * 拦截器就是AOP(Aspect-Oriented Programming)的一种实现.(AOP是指用于在某个方法或字段被访问之前,进行拦截然后在之前或之后加入某些操作.) * ...