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_A1094#The Largest Generation

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

  4. PAT1094:The Largest Generation

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

  5. PAT 1094 The Largest Generation[bfs][一般]

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

  6. pat1094. The Largest Generation (25)

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

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

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

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

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

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

随机推荐

  1. CRM系统数据授权

    1.新建角色,华东二区 2.业务对象中找到客户管理 3.在数据范围中新建数据规则,并进行设置 4.点击授权后,生效. 另:数据权限设置

  2. springboot 如何操作redis

    1.首先应该引入 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  3. 在编写wpf界面时候中出现如下错误: 类型引用不明确。至少有两个名称空间(“System.Windows”和“System.Windows”)中已出现名为“VisualStateManager”的类型。请考虑调整程序集 XmlnsDefinition 特性。

    wpf中类型引用不明确.至少有两个名称空间(“System.Windows”和“System.Windows”)中已出现名为“VisualState 你是不是用了WPFToolKit?如果是的,那原因 ...

  4. Python给照片换底色(蓝底换红底)

    环境要求 Python3 numpy函数库 opencv库 安装 下载适应版本的numpy函数库,我电脑是WIN10 64位,安装的函数库是 numpy-1.13.1+mkl-cp36-cp36m-w ...

  5. MyBatis基础:MyBatis动态SQL(3)

    1. 概述 MyBatis中动态SQL包括元素: 元素 作用 备注 if 判断语句 单条件分支判断 choose(when.otherwise) 相当于Java中的case when语句 多条件分支判 ...

  6. 莫烦scikit-learn学习自修第六天【特征值矩阵标准化】

    1.代码实战 #!/usr/bin/env python #!_*_coding:UTF-8 _*_ import numpy as np from sklearn import preprocess ...

  7. phonegap-plugin-contentsync

    一.API 1.ContentSync.sync(options) options.src : 字符串类型  (必选项)远程托管内容的URL.更新一个生产环境下的APP,常使用HTTPS option ...

  8. Ajax之Jquery封装使用举例

    <html> <head> <meta charset="UTF-8"> <title>登陆页面</title> < ...

  9. GLSL 变量属性

    1. attribute变量为这个attribute变量指定一个位置(用无符号值表示):glBindAttribLocation利用这个“位置”来指定需要传给shader里的attribue变量的数据 ...

  10. JS的初步了解

    JavaScript 是互联网上最流行的脚本语言,这门语言可用于 HTML 和 web,更可广泛用于服务器.PC.笔记本电脑.平板电脑和智能手机等设备.JavaScript 是脚本语言 HTML 中的 ...