题目如下:

#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. 知识点简单总结——FWT(快速沃尔什变换),FST(快速子集变换)

    知识点简单总结--FWT(快速沃尔什变换),FST(快速子集变换) 闲话 博客园的markdown也太傻逼了吧. 快速沃尔什变换 位运算卷积 形如 $ f[ i ] = \sum\limits_{ j ...

  2. 论文翻译:2021_Acoustic Echo Cancellation with Cross-Domain Learning

    论文地址:https://graz.pure.elsevier.com/en/publications/acoustic-echo-cancellation-with-cross-domain-lea ...

  3. Mybatis Plus使用租户过滤无效解决方案

    异常内容: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Pe ...

  4. redis 淘汰策略有哪些?

    noeviction: 不删除策略, 达到最大内存限制时, 如果需要更多内存, 直接返回错误信息. 大多数写命令都会导致占用更多的内存(有极少数会例外, 如 DEL ). allkeys-lru: 所 ...

  5. 推荐几个免费的在线学习IT技能视频网站:

    1.慕课网:http://www.imooc.com/course/list 2.极客学院:http://www.jikexueyuan.com/ 3.百度传课:http://www.chuanke. ...

  6. MySQL 支持事务吗?

    在缺省模式下,MySQL 是 autocommit 模式的,所有的数据库更新操作都会即时 提交,所以在缺省情况下,MySQL 是不支持事务的. 但是如果你的 MySQL 表类型是使用 InnoDB T ...

  7. Google Translate寻找之旅

    须知 网站:https://translate.google.de/ TK对应入口函数:teanslate_m_zh_CN文件/vu函数 TKK对应文件:/index页面,直接搜索TKK值即可 Goo ...

  8. 你能保证 GC 执行吗?

    不能,虽然你可以调用 System.gc() 或者 Runtime.gc(),但是没有办法保证 GC 的执行.

  9. mapper.xml文件中标签没有提示的解决

    1.首先我们来看看mapper.xml的头文件 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTY ...

  10. springboot远程debug调试

    案例代码: https://www.cnblogs.com/youxiu326/p/sb_promotion.html 1.首先去编辑器打开项目    2.打开Edit Configurations ...