PAT练习——1094 The Largest Generation (25 point(s))
题目如下:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int book[100];
vector<int> vi[100];
void dfs(int index, int level){
book[level]++;//第一层肯定是有的,即根节点
for(int i = 0; i < vi[index].size(); i++){
dfs(vi[index][i], level + 1);
}
}
int main(){
int n, m, a, k, ch;
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a >> k;//k指的是每一个非孩子节点的孩子节点的数量
for(int j = 0; j < k; j++){
cin >> ch;//ch指的上一个输入的每一位孩子节点
vi[a].push_back(ch);//输入每一行的孩子之后,将其塞入每个父母的变长数组后面
}
}
dfs(1, 1);
int maxnum = 0, maxid = 1;
for(int f = 0; f < 100; f++){
if(book[f] > maxnum){
maxnum = book[f];
maxid = f;
}
}
cout << maxnum << " " << maxid;
return 0;
}
重要的思路如下:

PAT练习——1094 The Largest Generation (25 point(s))的更多相关文章
- 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甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- 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 Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- 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 甲级 1094 The Largest Generation
https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...
- 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)
题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...
随机推荐
- 航模电池平衡头接线,1S-6S原理图
1-4S平衡头接线 S数代表几级锂电池串联,比如3S代表串联了3级,所以总电压为3*3.7V=11.4V.(每一级可能是多个电芯并联) 图源:百度贴吧 图源:5imx论坛 3S电池示例 B6充电器
- MyISAM 表格将在哪里存储,并且还提供其存储格式?
每个 MyISAM 表格以三种格式存储在磁盘上: ·".frm"文件存储表定义 ·数据文件具有".MYD"(MYData)扩展名 索引文件具有".MY ...
- 面试问题之C++语言:多态
什么是多态? 概念:同一操作作用于不同的对象,可以有不同的解释,产生不同的执行结果,这就是多态性.简单的说,就是用基类的引用指向子类的对象. 为什么要用多态呢? 原因:封装可以隐藏实现细节,使得代码模 ...
- MySQL 里有 2000w 数据,redis 中只存 20w 的数据,如 何保证 redis 中的数据都是热点数据?
Redis 内存数据集大小上升到一定大小的时候,就会施行数据淘汰策略. 相关知识:Redis 提供 6 种数据淘汰策略: volatile-lru:从已设置过期时间的数据集(server.db[i]. ...
- Redis 如何设置密码及验证密码?
设置密码:config set requirepass 123456 授权密码:auth 123456
- 如何设置出IDEA中VCS下的Enable Version Control Intergration
File–>settings–>Version Control
- 1、Jetson Nano 远程桌面XP问题
jeston nano上网 方法3(最简单的方法) 最简单的方法真的特简单,用USB数据线连接主板的USB接口以及手机,打开手机的USB共享即可,若要使用静态IP,可在主板上修改配置文件,接口一般为u ...
- ip地址与子网掩码概述
IP地址: IP地址(Internet Protocol):IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个逻辑地址,以此来屏蔽物理地址的差异. IP地址分为五 ...
- scanf()格式化输入
scanf();有种带[]的格式化输出方式 此格式控制符的基本格式为:%[scanfset] #include<stdio.h> int main() { char str[100] ; ...
- react 实用项目分享-mock server
使用react16+router4+mobx+koa2+mongodb做的mock平台 moapi-cli 本地工具版,一行命令 ,方便个人使用 安装 npm i moapi-cli -g 使用 mo ...