题目如下:

#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))的更多相关文章

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

  2. PAT甲级——1094 The Largest Generation (树的遍历)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...

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

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

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

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

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

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

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

  7. 1094. The Largest Generation (25)

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

  8. PAT 甲级 1094 The Largest Generation

    https://pintia.cn/problem-sets/994805342720868352/problems/994805372601090048 A family hierarchy is ...

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

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

随机推荐

  1. KVM虚拟机cpu资源限制和vcpu亲缘性绑定

    前言 KVM中添加的实例存在资源分布不均的情况,这样如果有消耗资源的实例会影响到其他实例的服务正常运行,所以给kvm做资源限制是很有必要的,下面记录一下在centos7中KVM环境下使用cgroup限 ...

  2. 『忘了再学』Shell基础 — 5、Bash基本功能(命令的别名和常用快捷键)

    目录 1.给命令设置别名 (1)设置别名的命令格式 (2)命令别名永久生效 (3)别名的优先级 2.Bash常用快捷键 1.给命令设置别名 Linux系统的命令别名我们之前已经说过了,这里再过一边. ...

  3. Java中hashCode、equals、==的区别

    ref:http://www.cnblogs.com/skywang12345/p/3324958.html 1.==作用: java中的==用来判断两个对象的地址是否相等:当对象是基本数据类型时,可 ...

  4. 用TLS/SSL保证EMQ的网络传输安全

    作为基于现代密码学公钥算法的安全协议,TLS/SSL能在计算机通讯网络上保证传输安全,EMQ的MQTT broker支持TLS,也可以用这种方式来确保传输安全. 参考官网:https://www.em ...

  5. vue开发chrome扩展,数据通过storage对象获取

    开发chrome插件时遇到一个问题,那就是单文件组件的data数据需要从chrome提供的storage对象中获取,但是 chrome.storage.sync.get 方法是异步获取数据的,需要通过 ...

  6. 面试问题之计算机网络:TCP如何保证数据可靠传输

    转载于:https://blog.csdn.net/liuchenxia8/article/details/80428157 TCP协议传输的特点主要就是面向字节流.传输可靠.面向连接. TCP保证数 ...

  7. 为什么需要域驱动设计(DDD)?

    我们需要 DDD 的因素 – 微服务面试问题

  8. CAS和CAP代表的作用

    CAS(自旋锁):https://www.jianshu.com/p/ab2c8fce878b CAP原则:https://baike.baidu.com/item/CAP原则/5712863?fr= ...

  9. 速看,ElasticSearch如何处理空值

    大家好,我是咔咔 不期速成,日拱一卒 在MySQL中,十分不建议大家给表的默认值设置为Null,这个后期咔咔也会单独出一期文章来说明这个事情. 但你进入一家新公司之前的业务中存在大量的字段默认值为Nu ...

  10. ROS学习文章

    ros机器人到底有没有必要学习?