1094 The Largest Generation (PAT甲级)

news/2025/3/15 6:40:25/

挽救自信心的题...

#include <cstdio>
#include <vector>
#include <map>
const int MAXN = 100;int N, M, K, id, maxP, maxLevel;
std::vector<int> vec[MAXN];
std::map<int, int> mp;void dfs(int p, int l){for(int i = 0; i < vec[p].size(); ++i){mp[l + 1]++;dfs(vec[p][i], l + 1);}
}int main(){scanf("%d %d", &N, &M);for(int i = 0; i < M; ++i){scanf("%d %d", &id, &K);vec[id].resize(K);for(int j = 0; j < K; ++j){scanf("%d", &vec[id][j]);}}mp[1]++;dfs(1, 1);maxP = 0;for(auto it = mp.begin(); it != mp.end(); ++it){if(it->second > maxP){maxP = it->second;maxLevel = it->first;}}printf("%d %d", maxP, maxLevel);return 0;
}

题目如下:

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

http://www.ppmy.cn/news/243380.html

相关文章

苹果手机计算机按出错误,苹果手机现惊天Bug:iOS 11计算器竟会因手速太快而出错...

9月20日凌晨&#xff0c;苹果正式推送了iOS 11系统&#xff0c;新增了系统录屏、GIF图片动态显示、截图标注等多个贴心功能。不过&#xff0c;另一方面&#xff0c;这个新系统存在很多Bug&#xff0c;让碰到的用户叫苦不迭。 近日&#xff0c;iOS 11的系统计算器上又出现了一个…

苹果手机怎么关机重启

产品型号&#xff1a;iPhone 12 系统版本&#xff1a;iOS 14.7 苹果手机关机重启总共分为3个步骤&#xff0c;具体的操作方法如下&#xff1a; 1、要关机的话&#xff0c;需要同时按下机身左侧的“音量”按钮和电源按钮。 2、当看到屏幕上出现“滑动来关机”选项时&#xff…

苹果手机验机教程

苹果手机验机教程 一、快递开封二、封装验收后操作三、开机验收辨别手机类型识别问题机 四、验证二手机 一、快递开封 1、首先当着快递员拆开外包装&#xff0c;在未拆手机盒膜的时拿捏手机盒&#xff0c;如果机盒棱角分明&#xff0c;进行下一步看封装。 2、封边在手机盒四个…

苹果手机投影_手机和投影同时用流量能否投屏

原标题&#xff1a;手机和投影同时用流量能否投屏 手机和投影同时用流量能否投屏 用手机流量可以投屏投影仪吗&#xff1f;答案必须是可以的。市场上有一小部分手机支持HDMI输出&#xff0c;通过HDMI线轻松连接手机和投影仪。不过大多数情况下&#xff0c;我们还是会选择通过无…

苹果手机各种型号图片_一图看懂iPhone各机型机身尺寸大小对比!

原标题:一图看懂iPhone各机型机身尺寸大小对比! 本周二,苹果一口气发布了四款新iPhone,包括:5.4英寸的iPhone 12mini、6.1英寸的iPhone 12、6.1英寸的iPhone 12 Pro以及6.7英寸的iPhone 12 Pro Max。 iPhone 12系列的发布,也让用户在购买iPhone手机时比以往增加了更多的尺…

苹果手机配对手表总是显示服务器,苹果手表配对失败,为什么iwatch跟手机总是配对...

提起苹果手表配对失败,大家都知道,有人问苹果手表重新配对手机,一直不成功,停留在这个界面怎么办,谢谢大神,另外,还有人想问苹果手表输入ID无法匹配是怎么回事,你知道这是怎么回事?其实苹果手机怎么和苹果手表配对不上,下面就一起来看看为什么iwatch跟手机总是配对失…

iphone html 手机震动,​苹果手机震动器在哪里?如何设置与关闭?

许多用苹果手机的老是搞不懂明明设置了手机静音&#xff0c;但还是会振动&#xff0c;那么该怎么给它关闭呢&#xff1f;苹果手机的静音只是振动铃声的静音&#xff0c;并不会关闭振动功能&#xff0c;想要关闭振动需要另外设置。那么该怎么做呢&#xff1f;下面贤集网小编为大…

Redis 高级数据结构 GEO

​ Redis 3.2版本提供了GEO(地理信息定位)功能&#xff0c;支持存储地理位置信息用来实现诸如附近位置、摇一摇这类依赖于地理位置信息的功能。地图元素的位置数据使用二维的经纬度表示&#xff0c;经度范围(-180, 180]&#xff0c;纬度范围(-90,90]&#xff0c;纬度正负以赤道…