题目如下:

#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. linux的一些sao东西

    1.sys命令的目录 /usr/include/asm-generic

  2. 27.Java 飞机游戏小项目

    开篇 游戏项目基本功能开发 飞机类设计 炮弹类设计 碰撞检测设计 爆炸效果的实现 其他功能 计时功能 游戏项目基本功能开发 这里将会一步步实现游戏项目的基本功能. 使用 AWT 技术画出游戏主窗口 A ...

  3. Map的野路子

    首先有一张user数据表,数据库名称为mybatis,数据如下: 我们使用以下两种方式实现数据更新的操作. 方式一 UserMapper.java如下: /** * @description: 更改用 ...

  4. jvm-learning-类加载子系统

    类加载子系统的作用 类加载器ClassLoader角色 类的加载过程(广义加载)  加载  加载.class文件的方式 连接Linker 初始化  注意:如果类种没有变量赋值动作和静态代码块的语句是不 ...

  5. 解释 AOP 模块?

    AOP 模块用于发给我们的 Spring 应用做面向切面的开发, 很多支持由 AOP 联 盟提供,这样就确保了 Spring 和其他 AOP 框架的共通性.这个模块将元数据编 程引入 Spring.

  6. 如何将springboot工程打包成war包并且启动

    将项目打成war包,放入tomcat 的webapps目录下面,启动tomcat,即 可访问. 1.pom.xml配置修改 <packaging>jar</packaging> ...

  7. ACM中的位运算技巧

    听说位运算挺好玩的,那这节总结一下ACM中可能用到的位运算技巧. XOR运算极为重要!!(过[LC136](只出现一次的数字 - 力扣(LeetCode)):数组中每个数字都出现两次,只有一个出现一次 ...

  8. Leetcode刷题之矩阵中的指针用法

    矩阵中的指针用法 1 快慢指针 ​ Leetcode27移除元素 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度.不要使用额外的数组 ...

  9. carsim输入输出变量

    来自:https://wenku.baidu.com/view/3405ded5443610661ed9ad51f01dc281e43a5673.html 输出量

  10. 标签页tab.js 在栏目之间切换,局部变化

    1.在使用bootstrap 中,我们会用到在栏目之间切换,来刷新页面的局部,可以使用下面的方法 <link rel="stylesheet" href="http ...