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 ...
随机推荐
- git 多人在同一分支上迭代开发时,如何保证分支提交历史保持线性
背景 最近我们组几个同事都投入到了一个新项目,互相之间的功能耦合比较紧密,因此,是打算从master上新拉一个分支,可以理解为我们几个人的开发分支,以develop代替. 一开始,我们是打算像svn那 ...
- String s = new String("xyz");创建了几个字符串对象?
两个对象,一个是静态区的"xyz",一个是用new创建在堆上的对象.
- 使用 rabbitmq 的场景?
1.服务间异步通信 2.顺序消费 3.定时任务 4.请求削峰
- mybatis 自定义插件的使用
今天看了别人的mybatis的教学视频,自己手写了一个简单的自定义的插件,有些细节记录一下. 先看下mybatis的插件的一些说明: MyBatis 允许你在已映射语句执行过程中的某一点进行拦截调用. ...
- SqlMapConfig.xml文件详解
SqlMapConfig.xml 是 mybatis 的全局配置文件,配置内容如下: properties(属性) settings(全局配置参数) typeAliases(类型别名) typeHan ...
- 从0搭建vue后台管理项目到颈椎病康复指南(一)
网上搜索了很久Vue项目搭建指南,并没有找到写的比较符合心意的,所以打算自己撸一个指南,集合众家之所长(不善于排版,有点逼死强迫症,如果觉得写的有问题,可以留言斧正,觉得写的太差的,可以留言哪里差, ...
- ES6-11学习笔记--Map
Map:一种新的数据结构 常用方法 遍历 应用场景 WeakMap 常用方法: let map = new Map() let obj = { name: '张三' } map.set(obj, ...
- ASP.NET WebAPI解决跨域问题
跨域是个很蛋疼的问题...随笔记录一下... 一.安装nuget包:Microsoft.AspNet.WebApi.Core 二.在Application_Start方法中启用跨域 1 protect ...
- 动态添加HTML时onclick函数参数传递
onclick函数动态传参 1.参数为数值类型时: var tmp = 123; var strHTML = "<div onclick=func(" + tmp + &qu ...
- js修改html中class属性
document.getElementById("tr").setAttribute("class","styleclass"); 其中 ...