1094. The Largest Generation (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

提交代码

姥姥教的方法,顺便用一下。

last:更新前,本层最后一个元素
tail:下一层当前最后一个元素
floor:指向当前的层数
 #include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
vector<int> v[];
int main(){
int n,m;
scanf("%d %d",&n,&m);
int i,num,count,in;
for(i=;i<m;i++){
scanf("%d %d",&num,&count);
while(count--){
scanf("%d",&in);
v[num].push_back(in);
}
}
queue<int> q;
q.push();
int last=,tail,floor=,cur,maxcount=,maxfloor=,curcount=;
while(!q.empty()){
cur=q.front();
q.pop();
for(i=;i<v[cur].size();i++){
q.push(v[cur][i]);
tail=v[cur][i];
curcount++;
}
if(last==cur){
last=tail;
floor++;//point to next floor
if(curcount>maxcount){
maxcount=curcount;
maxfloor=floor;
}
curcount=;
}
}
printf("%d %d\n",maxcount,maxfloor);
return ;
}

pat1094. The Largest Generation (25)的更多相关文章

  1. PAT1094:The Largest Generation

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

  2. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

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

  4. 1094. The Largest Generation (25)

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

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

  6. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  7. 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)

    题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...

  8. The Largest Generation (25)(BFS)(PAT甲级)

    #include<bits/stdc++.h>using namespace std;int n,m,l,t;int a[1307][137][67];int vis[1307][137] ...

  9. 【PAT甲级】1094 The Largest Generation (25 分)(DFS)

    题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...

随机推荐

  1. winfrom浏览器控件

    (1)webbrowser 在ie的基础上开发出来的,一般情况下很好用,特殊情况下没法用,一堆坑,h5支持效果不好 使用:直接拖控件就好了 (2)WebKit .NET http://webkitdo ...

  2. Aspose.Words CookieBook

    Aspose.Words.dll  版本 13.1.0.0 [原创]Aspose.Words组件介绍及使用—基本介绍与DOM概述 插入分页符 DocumentBuilder builder = new ...

  3. ueditor UEditor的setContent的时候报错

    今天在使用UEditor的setContent的时候报错,报错代码如下 TypeError: me.body is undefined 或 Uncaught TypeError: Cannot set ...

  4. framwork maven的配置及使用

    maven的配置及使用 一.什么是maven: 我们在开发项目的过程中,会使用一些开源框架.第三方的工具等等,这些都是以jar包的方式被项目所引用,并且有些jar包还会依赖其他的jar包,我们同样需要 ...

  5. InnoDB记录压缩及使用分析

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 这篇文章,源于RDS组内的一次饭后闲聊,两位小伙伴在探讨InnoDB启用压缩后的种种,比如在磁盘上是怎么存放 ...

  6. c++滚动数组

    说来惭愧,我老早以前就学习了dp,可直到最近才知道滚动数组. 所以说,滚动数组是什么呢? 它是一种优化dp空间复杂度的思想. 在dp转移时,我们往往不需要之前推的所有的,而是只需要前一两个转移的. 我 ...

  7. 利用excel制作二维码

    1 将想要通过扫描二维码访问的目标网址放入A1单位格 2 在excel 编辑区右击选择“自定义功能区” 3 然后将“开发者工具”选上 4 点击菜单栏的“开发者工具---插入--->其他控件” 5 ...

  8. Vue2.0学习--Vue数据通信详解

    一.前言 组件是 vue.js最强大的功能之一,而组件实例的作用域是相互独立的,这就意味着不同组件之间的数据无法相互引用.组件间如何传递数据就显得至关重要.本文尽可能罗列出一些常见的数据传递方式,如p ...

  9. oracle 集群jndi部署方式

    一般部署oracle   jndi的方式: ...jdbc.url=jdbc:oracle:thin:@10.196.20.xx:1521:SID ... 集群部署方式 : ... jdbc.url= ...

  10. P3321 [SDOI2015]序列统计 FFT+快速幂+原根

    \(\color{#0066ff}{ 题目描述 }\) 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S.小C用这 ...