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 ...
随机推荐
- 【开源项目5】测滑菜单MenuDrawer的使用以及解析
在安卓中左右侧滑菜单的使用用的比ios多得多,可能是谷歌带的头吧,几乎所有的谷歌应用都有侧滑菜单.谷歌没有开放这个源码,在一个成熟的开源代码出现之前,大家都是各自为战,偶尔能看到一个勉强实现了的.Me ...
- page59-一种能够累加数据的ADT(可视化版本) [可用于数据挖掘可视化工具]
public class VisualAccumulator VisualAccumulator() 创建一个累加器 void addDataValue(double val) 添加一个新的数据值 d ...
- (ASP.NET)总结MVC中@Html表单用法
1.当type类型是text时:@Html.TextBoxFor(model => Model.Name,new{@style = "width: 50px;", @clas ...
- VB.NET 小程序 1
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ...
- MySQL分区表的使用
MySQL使用分区表的好处: 1,可以把一些归类的数据放在一个分区中,可以减少服务器检查数据的数量加快查询. 2,方便维护,通过删除分区来删除老的数据. 3,分区数据可以被分布到不同的物理位置,可以做 ...
- 关于HTML中浮动与清除的思考
布局时需要利用浮动(float)的属性,同时我们需要一个清除浮动(clear)与之配合才能达到预期的目标. w3s上关于float和clear的定义分别为:float:float 属性定义元素在哪个方 ...
- 深入理解ThreadLocal(转)(2015年06月11日)
注明:转自:http://my.oschina.net/clopopo/blog/149368 学习一个东西首先要知道为什么要引入它,就是我们能用它来干什么.所以我们先来看看ThreadLocal对我 ...
- JavaScript--正则表达式(笔记)
一 什么是正则表达式 // 正则表达式(regular expression)是一个描述字符模式的对象; // JS定义RegExp类表示正则表达式; // String和RegExp都定义了使用正则 ...
- 二十二、android中application标签说明
<application> <applicationandroid:allowClearUserData=["true" | "false"] ...
- 英特尔® 实感™ SDK R4 (v.6.0) 的全新特性
原文地址 第四版 (R4) 黄金版 SDK (版本 6.0)现已面向英特尔® 实感TM F200 摄像头推出,并面向英特尔® 实感TM 后置 R200 摄像头发布黄金版本. 请注意,F200 OR R ...