1094. The Largest Generation (25)
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 (<100) 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 (<N) 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 (>0) 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
#include<string>
#include<iostream>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std; struct node
{
vector<int> child;
}; node Tree[];
int Level[];
int MAX = -;
void DFS(int n,int level)
{
if(MAX < level)
MAX = level;
++Level[level];
for(int i = ;i < Tree[n].child.size() ;++i)
DFS(Tree[n].child[i],level+);
}
int main()
{
int n,m,tid,num,id;
scanf("%d%d",&n,&m);
for(int i = ;i < m ;++i)
{
scanf("%d%d",&id,&num);
for(int k = ;k < num;++k)
{
scanf("%d",&tid);
Tree[id].child.push_back(tid);
}
}
DFS(,);
int maxL = -;
int index = -;
for(int i = ; i <= MAX;++i)
{
if(Level[i] > maxL)
{
maxL = Level[i];
index = i;
}
}
printf("%d %d\n",maxL,index);
return ;
}
1094. The Largest Generation (25)的更多相关文章
- PTA甲级1094 The Largest Generation (25分)
PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...
- 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 ...
- PAT Advanced 1094 The Largest Generation (25) [BFS,DFS,树的遍历]
题目 A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level ...
- PAT (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)
题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- PAT练习——1094 The Largest Generation (25 point(s))
题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...
- 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 ...
随机推荐
- 《算法导论》习题解答 Chapter 22.1-4(去除重边)
思路:重开一个新图,按着邻接列表的顺序从上到下遍历,每遍历一行链表前,清空visited数组,如果没有访问过这个元素,则加入新图,如果已经访问过了(重边),则不动. 伪代码: 复杂度:O(V+E) f ...
- js 每秒刷新系统时间,可停止
<title>无标题页</title> <script language="javascript" type="text/javascrip ...
- VMware系统运维(二十)部署虚拟化桌面Horzion View 5.2 HTML Access进行连接测试
1.通过浏览器打开Horzion View登录界面,https://conntionserver.testad.local,点击"VMware Horzion View HTML Acces ...
- React Native学习-调取摄像头第三方组件:react-native-image-picker
近期做的软件中图片处理是重点,那么自然也就用到了相机照相或者相册选取照片的功能. react-native中有image-picker这个第三方组件,但是0.18.10这个版本还不是太支持iPad. ...
- rfc 标准文档目录
1. xmpp的文档 (3920版本) https://tools.ietf.org/html/rfc3920 2. MQTT 3. SIP
- canvas基础2--绘制图形
栅格 绘制矩形 不同于SVG,HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径.不过,我们拥有众多路径生成的方法让复杂图形的绘制成为了可能. 首先 ...
- Discuz!图片查看插件(支持鼠标缩放、实际大小、旋转、下载)
Discuz!图片查看插件(支持鼠标缩放.实际大小.旋转.下载) 图片查看是网站中的常用功能,用于展示详细的图片.在discuz图片插件的基础上进行了改造,因此这篇文章主要从以下几个方面来讨论图片查看 ...
- Part 10 Stored procedures in sql server
Stored procedures in sql server Stored procedures with output parameters Stored procedure output par ...
- Android之开源项目优秀项目篇
本文转自:http://www.trinea.cn/android/android-open-source-projects-excellent-project/ 记录的项目主要依据是项目有意思或项目 ...
- MVC System.Web.Mvc.ModelClientValidationRule”同时存在
错误 2280 类型“System.Web.Mvc.ModelClientValidationRule”同时存在于“C:\Program Files\Microsoft ASP.NET\ASP.NET ...