1094. The Largest Generation (25)
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<string>
#include<iostream>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std; struct node
{
vector<int> child;
}; node Tree[];
int Level[];
int MAX = -;
void DFS(int n,int level)
{
if(MAX < level)
MAX = level;
++Level[level];
for(int i = ;i < Tree[n].child.size() ;++i)
DFS(Tree[n].child[i],level+);
}
int main()
{
int n,m,tid,num,id;
scanf("%d%d",&n,&m);
for(int i = ;i < m ;++i)
{
scanf("%d%d",&id,&num);
for(int k = ;k < num;++k)
{
scanf("%d",&tid);
Tree[id].child.push_back(tid);
}
}
DFS(,);
int maxL = -;
int index = -;
for(int i = ; i <= MAX;++i)
{
if(Level[i] > maxL)
{
maxL = Level[i];
index = i;
}
}
printf("%d %d\n",maxL,index);
return ;
}
1094. The Largest Generation (25)的更多相关文章
- PTA甲级1094 The Largest Generation (25分)
PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...
- 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 ...
- 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 ...
- PAT (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)
题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- PAT练习——1094 The Largest Generation (25 point(s))
题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...
- 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 ...
随机推荐
- java 生成UUID
UUID(Universally Unique Identifier)全局唯一标识符,是一个128位长的数字,一般用16进制表示. 算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成UUID, ...
- ValidateRequest="false" 无效
在做牛腩新闻发布系统的时候,部分同学可能会遇到这样的情况: 从客户端(ContentPlaceHolder1_m_ContentPlaceHolder_ftbContent="<P&g ...
- angularJS图表-angular-flot
1.首先需要在项目中引入的js文件有 <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.mi ...
- 管理后台-第二部分:Custom sections in Umbraco 7 – Part 2 the views(翻译文档)
在上一篇文章中我们讨论了怎样在我们Umbraco7.0版本中去添加一个新的自定义的应用程序(或部分)和如何去定义一个树.现在我将给你展示你改何如添加视图,来使你的内容可以做一些更有意义的事情. The ...
- Linux(CentOS)同步时间
可参考:http://www.ntp.org.cn/ http://www.cnblogs.com/pipelone/archive/2009/06/17/1505002.html 当前已提供的各国N ...
- UITabBar实现自定义背景及UITabBarItem自定义图片和字体
UITabBarItem *firstItem = [[UITabBarItem alloc]initWithTitle:]; //设置字体颜色(后面设置字体状态)(UITextAttributeTe ...
- parseInt在IE8转换返回不相等(parseInt("08")返回0等以0开头大于7的数字串)
描述 在IE8内核下parseInt("08")返回0,等以0开头大于7的数字串返回的值不相等 解决方法 parseInt当不指定radix时,当以0x开头时,s按照十六进制计算的 ...
- DOM 1
首先getAttribute setAttribute只能被元素节点对象调用.(属性节点和文本节点调用不了) 我们可以通过一下三种方式得到元素: document.getElementById(); ...
- PHP与javascript实现变量交互
<?php /** * 本例是PHP和javascript交互的例子,php中的值赋给js变量中,前提是这个php变量必须有值才行,就算是假分支中. * 比如php中的$flags在本例中为tr ...
- 怎么手写Ajax实现异步刷新
所谓的异步刷新,就是不刷新整个网页进行更新数据. 只有通过js才能实现Ajax,进而实行异步刷新 表单提交数据和Ajax提交数据的区别:表单提交是提交的整个页面中的数据,提交数据之后会抛弃之前的页面( ...