A1094. The Largest Generation
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<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef struct{
int data;
vector<int>child;
}node;
node tree[];
int N, M, width[] = {}, maxDepth = -;
void DFS(int s, int dp){
if(s > N)
return;
width[dp]++;
if(dp > maxDepth){
maxDepth = dp;
}
for(int i = ; i < tree[s].child.size(); i++){
DFS(tree[s].child[i], dp + );
}
}
int main(){
scanf("%d%d", &N, &M);
for(int i = ; i < M; i++){
int id, K, temp;
scanf("%d%d", &id, &K);
tree[id].data = id;
for(int j = ; j < K; j++){
scanf("%d", &temp);
tree[id].child.push_back(temp);
}
}
DFS(,);
int index = -, max = -;
for(int i = ; i <= maxDepth; i++){
if(width[i] > max){
max = width[i];
index = i;
}
}
printf("%d %d", max, index);
cin >> N;
return ;
}
A1094. The Largest Generation的更多相关文章
- 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 ...
- PAT甲级——A1094 The Largest Generation
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- PAT_A1094#The Largest Generation
Source: PAT A1094 The Largest Generation (25 分) Description: A family hierarchy is usually presented ...
- 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 ...
随机推荐
- Ionic1.x项目中的Installing npm packages问题
与npm远程源有关,可以通过cnpm来解决: 一.ionic start myApp blank --skip-npm(跳过Installing npm packages会产生的问题): 二.然后进入 ...
- python学习笔记(11)--文件与数据格式化
文件的概念: 文件是数据的抽象和集合,是存储在辅助存储器上的数据序列,文件是数据存储的一种形式,文件的展现形态,文本文件和二进制文件. 文本文件输出: f.txt文件保存:“我是中国人” >&g ...
- mysql对身份证号码进行脱敏处理
select * from test 格式:INSERT(str,pos,len,newstr) 解释: str:查询的例 pos:起始位置 len:从起始位置开始被后面newstr替换的长度 new ...
- log4j2.xml
<?xml version="1.0" encoding="UTF-8"?> <configuration status="info ...
- 阿里p3c(代码规范,eclipse插件、模版,idea插件)
阿里p3c 一.说明 代码规范检查插件p3c,是根据<阿里巴巴Java开发手册>转化而成的自动化插件. (高级黑:P-3C“Orion”,反潜巡逻机,阿里大概取p3c先进,监测,发现潜在问 ...
- crontab 从nano 转换为 vim
crontab默认编辑器为nano,不方便使用. 修改crontab默认编辑器为vi或者其他的编辑器. export EDITOR="/usr/bin/vim" ; cront ...
- 洛谷 p1019 单词接龙
题目描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次),在两个单词相连时,其重合 ...
- Mybatis -SqlMapConfig.xml环境配置
SqlMapConfig.xml的配置内容和顺序如下(顺序不能乱): Properties(属性) Settings(全局参数设置) typeAliases(类型别名) typeHandlers(类型 ...
- Modbus CRC 16 (C#)
算法 1.预置一个值为 0xFFFF 的 16 位寄存器,此寄存器为 CRC 寄存器. 2.把第 1 个 8 位二进制数据(即通信消息帧的第 1 个字节)与 16 位的 CRC 寄存器相异或,异或的结 ...
- 解决面板里没有network manager图标的问题 ,也就是在桌面环境下,没有那个网络图标
在安装好了桌面之后,竟然发现没有那个连接网络的图标,本来想连接无限网络.可是.......如果去手动命令行下去配置这个连接wifi有些麻烦,所以我还是去找解决办法了 我执行了一条命令就解决了 gcon ...