A1094. The Largest Generation

时间:2021-12-04 16:46:47

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 (&lt100) 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 (&ltN) 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 (&gt0) 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的更多相关文章

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

  2. PAT甲级——A1094 The Largest Generation

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

  3. PAT&lowbar;A1094&num;The Largest Generation

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

  4. PAT1094&colon;The Largest Generation

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  5. PAT 1094 The Largest Generation&lbrack;bfs&rsqb;&lbrack;一般&rsqb;

    1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...

  6. pat1094&period; The Largest Generation &lpar;25&rpar;

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  7. PAT甲级——1094 The Largest Generation &lpar;树的遍历&rpar;

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

  8. PAT &lpar;Advanced Level&rpar; Practise - 1094&period; The Largest Generation &lpar;25&rpar;

    http://www.patest.cn/contests/pat-a-practise/1094 A family hierarchy is usually presented by a pedig ...

  9. 1094 The Largest Generation ——PAT甲级真题

    1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...

随机推荐

  1. foreach遍历遇到的一个细节问题

    1.Invalid argument supplied for foreach()警告错误解决办法:foreach遍历之前添加is_array()判断

  2. 当局部变量遇上全局变量——extern及花括号用法举例

    请阅读以下代码并说出它的输出结果. #include <stdio.h> ; int foo() { ; { extern int val; printf("val_foo = ...

  3. codeforce 630N Forecast

    N. Forecast time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input ...

  4. Java实现文件的RSA和DES加密算法

    根据密钥类型不同将现代密码技术分为两类:对称加密算法(秘密钥匙加密)和非对称加密算法(公开密钥加密) 对称钥匙加密系统是加密和解密均采用同一把秘密钥匙,而且通信双方都必须获得这把钥匙,并保持钥匙的秘密 ...

  5. struts2原理分析

    正在使用struts之前,我们必须明白servlet执行.因为不管什么J2EE框架支持servlet的. 和servlet正在运行的进程.简单地说,例如,下面的: 1.server接收请求 2.一个过 ...

  6. Dragon Balls

    Dragon Balls Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. Linux 目录与文件管理

    1. 目录与路径1.1 相对路径与绝对路径1.2 目录的相关操作: cd, pwd, mkdir, rmdir1.3 关于执行文件路径的变量: $PATH2. 档案与目录管理2.1 档案与目录的检视: ...

  8. LeetCode 21&period; Merge Two Sorted Lists(c&plus;&plus;&rpar;

    要定义两个链表 判断时依次对应每一个链表的值进行判断即可. /** * Definition for singly-linked list. * struct ListNode { * int val ...

  9. &lbrack;Android&rsqb;Linux下WebRTC下载与编译

    1.硬盘空间: WebRTC官方原话: The checkout size is large due the use of the Chromium build toolchain and many ...

  10. redis在linux云服务器上完整的搭建步骤

    Redis的安装 搭建环境: 华为云linux服务器 Linux系统CneterOS-7.3 SSH客户端 Xshell6 安装c语言编译环境软件如下: 安装报错 然后找到了解决方法: 安装kerne ...