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 ...
随机推荐
- 屏幕尺寸,分辨率,PPI,像素之间的关系
什么是屏幕尺寸? 华为荣耀7的尺寸是5.2英寸.这个5.2英寸是手机屏幕对角线的长度. 1英寸(inch)=2.54厘米(cm) 什么是分辨率? 华为荣耀7的分辨率是1920PX*1080PX.像素是 ...
- Eclipse中安装插件的方法
eclipse插件的安装方法大体有以下三种: 第一种:直接复制法:假设你的Eclipse的在(C:\eclipse), 解压你下载的 eclipse 插件或者安装eclipse 插件到指定目录AA( ...
- 贪心——cf708b
先求0,1的个数,然后贪心输出01即可 #include<bits/stdc++.h> using namespace std; #define ll long long ll a,b,c ...
- 原生js 与 jQuery对比
1.原生JS与jQuery操作DOM对比 : https://www.cnblogs.com/QianBoy/p/7868379.html 2.比较jQuery与JavaScript的不同功能实 ...
- host文件是作用
什么是HOST文件:Hosts是一个没有扩展名的系统文件,其基本作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Host ...
- CSS:CSS 图像拼合技术
ylbtech-CSS:CSS 图像拼合技术 1.返回顶部 1. CSS 图像拼合技术 图像拼合 图像拼合就是单个图像的集合. 有许多图像的网页可能需要很长的时间来加载和生成多个服务器的请求. 使用图 ...
- CSS:CSS 轮廓(outline)
ylbtech-CSS:CSS 轮廓(outline) 1.返回顶部 1. CSS 轮廓(outline) 轮廓(outline)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用. ...
- nginx代理一个服务器上所有域名
1. 主配置文件不需要更改任何配置2. 在vhosts目录下需要建立两个文件,一个是servername 列表文件,一个是虚拟主机配置文件两个文件内容分别为 #() servername server ...
- 如何解决 react-create-app 里面的 no-unused-vars ?
如果每次启动都有一大串的no-unused-vars 是不是感觉特别烦,不用担心啦,有个配置可以解决它: 在Hbuild 里面可以新建一个 .eslintrc 其他文件(伤心的是我在webStorm ...
- Spring mvc Hello World
Spring mvc Hello World 添加依赖 <dependency> <groupId>org.springframework</groupId> &l ...