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

 #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int N, M, maxN = , resL = , root = , level[] = { }, manN[] = { };
vector<int>man[];
void BFS()
{
queue<int>q;
q.push(root);
level[root] = ;
manN[level[root]]++;
while (!q.empty())
{
root = q.front();
q.pop();
int temp = ;
for (auto v : man[root])
{
level[v] = level[root] + ;
manN[level[v]]++;//记录每一层的人数
if (man[v].size() > )
q.push(v);
}
}
} void DFS(int s,int l)
{
manN[l]++;//l层的人数
for (auto v : man[s])
DFS(v, l + );
} int main()
{
cin >> N >> M;
for (int i = ; i < M; ++i)
{
int a, b, k;
cin >> a >> k;
for (int j = ; j < k; ++j)
{
cin >> b;
man[a].push_back(b);
}
}
//BFS();
DFS(, );
for (int i = ; i <= N; ++i)
{
if (maxN < manN[i])
{
maxN = manN[i];
resL = i;
}
}
cout << maxN << " " << resL << endl;
return ;
}

PAT甲级——A1094 The Largest Generation的更多相关文章

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

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

  2. PAT 甲级 1094 The Largest Generation

    https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...

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

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

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

  5. A1094. The Largest Generation

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

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

  7. PAT练习——1094 The Largest Generation (25 point(s))

    题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...

  8. PAT_A1094#The Largest Generation

    Source: PAT A1094 The Largest Generation (25 分) Description: A family hierarchy is usually presented ...

  9. PAT甲级题解分类byZlc

    专题一  字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...

随机推荐

  1. DLL相关下断点

    加载DLL 的时候断: sxe ld:[dll] 卸载DLL 的时候断: sxe ud:[dll] 比如: sxe ld:wininet.dll  (在wininet.dll 被装载的时候断点) 这里 ...

  2. duboo注解使用详解

    一.背景 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行. 当越来越的的接口与实现类的增加后,duboo的xml配置会越来越多,为了防止 ...

  3. ES6 学习 -- 箭头函数(=>)

    (1).只有一个参数且只有一句表达式语句的,函数表达式的花括号可以不写let test = a => a; // 只有一个参数a,这里的表达式相当于 "return a" ( ...

  4. Docker学习のDocker中部署静态页网站

    前言:部署一个静态页网站,我们需要 常见映射80端口的交互式容器 安装Nginx(或其他服务器) 安装文本编辑器vim 创建静态页面 修改Ngnix的配置文件 运行Ngnix 验证网站的防高温 一.设 ...

  5. 如何使用maven打包

    使用maven打包有两种情况:不包括第三方jar包.包括第三方jar包 一般我们写程序,都会在IDEA上去调试,那么也就意味着,你需要将你所需要的jar包(第三方jar)全部给pom文件,否则是不能工 ...

  6. arm-linux-ar 和 arm-linux-ranlib 的使用

    静态库是在编译时需要的库. 1. 建立一个静态库 [arm@localhost gcc]#arm­linux­ar ­r libhello.a h1.o h2.o 2. 为静态库建立索引 [arm@l ...

  7. MySQL中查询所有数据库占用磁盘空间大小

    查询所有数据库占用磁盘空间大小的SQL语句: 复制代码 代码如下:select TABLE_SCHEMA, concat(truncate(sum(data_length)/1024/1024,2), ...

  8. grunt完整的配置demo

    const path = require('path') const fs = require('fs'); module.exports = function (grunt) { grunt.reg ...

  9. 浏览器自带记忆功能,使input颜色和字体丢失

    方法一 : 会有视觉上颜色的变化input:-internal-autofill-selected { /*内置阴影填充 背景颜色*/ box-shadow: inset 0 0 0 1000px # ...

  10. HTML 5 基础

    HTML 参考手册 HTML 5 视频 controls 属性供添加播放.暂停和音量控件. <video src="movie.ogg" width="320&qu ...