pat1094. The Largest Generation (25)
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
姥姥教的方法,顺便用一下。
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)的更多相关文章
- PAT1094:The Largest Generation
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- 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 ...
- 1094. The Largest Generation (25)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- 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 ...
- 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] ...
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
随机推荐
- easyUI 展开DataGrid里面的行显示详细信息
http://blog.csdn.net/yanghongchang_/article/details/7854156原著 datagrid 可以改变它的view(视图)去显示不同的效果.使用详细视图 ...
- linux手动安装配置 mysql5.7
本文原出处地址 https://www.cnblogs.com/mujingyu/p/7689116.html 一.安装前的检查 1.1 检查 linux 系统版本 [root@localhost ...
- jQuery实例代码-表单相关
select option 获取选中项的文本值 $("#ddl_GoOutReasonType option:selected").text() 根据索引定于option项 $(& ...
- 用Apache James 3.3.0 搭建个人邮箱服务器
准备域名 比如域名为example.net,则邮箱格式为test@example.net.在自己的域名管理界面,添加一条A记录(mail.example.net xxx.xxx.xxx.xxx),指 ...
- P4718 【模板】Pollard-Rho算法
题面 传送门 题解 题解 太神仙了学不来orz //minamoto #include<bits/stdc++.h> #define R register #define ll long ...
- Linux之sshkey密钥认证实战
在实际的生产环境中,经常会用到sshkey密钥认证实行数据分发数据等操作,还可以批量操作内网服务器,实行免密认证进行推送分发数据. 1.环境查看 分发服务器 节点服务器 2.服务器添加系统账号 3.生 ...
- curl抓取网页内容php
1.cURL curl是客户端向服务器请求资源的工具 2.cURL使用场景 网页资源:网页爬虫 webservice数据接口资源:动态获取接口数据 天气 号码归属地 ftp资源:下载ftp服务器里面 ...
- 10、OpenCV Python 图像二值化
__author__ = "WSX" import cv2 as cv import numpy as np #-----------二值化(黑0和白 255)---------- ...
- P2381 圆圆舞蹈
题意:一个圆,上面有n头牛(卧槽) 给出相邻两头牛顺时针的距离 问两只最远的牛的距离(min(顺时针距离,逆时针距离)) 最远距离一定$\le$距离和/2 先求个前缀和 那么问题转化为:找到 $s_j ...
- log4j配置文件及java调用 每个级别输出到不同的文件
#配置根Logger log4j.rootLogger = DEBUG , RollingFile,CONSOLE #文件大小达到一定尺寸的时候创建一个新的文件 log4j.appender.Roll ...