1094 The Largest Generation
题意:略。
思路:层序遍历;在结点中增加一个数据域表示结点所在的层次。
代码:
#include <cstdio> #include <queue> #include <vector> using namespace std; struct Node{ int layer; vector<int> child; }; vector<Node> tree(); ]={}; ,maxNum=; void levelOrderTraversal(int root) { queue<Node> q; tree[root].layer=; q.push(tree[root]); while(!q.empty()){ Node node=q.front(); q.pop(); level[node.layer]++; if(level[node.layer] > maxNum){ maxNum=level[node.layer]; maxLevel=node.layer; } for(auto it:node.child){ tree[it].layer=node.layer+; q.push(tree[it]); } } } int main() { int n,m; scanf("%d%d",&n,&m); int id,k,kid; ;i<m;i++){ scanf("%d%d",&id,&k); ;j<k;j++){ scanf("%d",&kid); tree[id].child.push_back(kid); } } levelOrderTraversal(); printf("%d %d\n",maxNum,maxLevel); ; }
1094 The Largest Generation的更多相关文章
- PAT 1094 The Largest Generation[bfs][一般]
1094 The Largest Generation(25 分) A family hierarchy is usually presented by a pedigree tree where a ...
- PAT甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- 1094 The Largest Generation ——PAT甲级真题
1094 The Largest Generation A family hierarchy is usually presented by a pedigree tree where all the ...
- 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 ...
- 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 ...
- PAT 1094. The Largest Generation (层级遍历)
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...
- 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 (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- djagno重写authenticate实现帐号和邮箱的多方式登录。
1.在users应用的view中重写authenticate: from django.contrib.auth.backends import ModelBackend from django.db ...
- windows下创建文件夹链接
mklink百度百科https://baike.baidu.com/item/mklink/566760?fr=aladdin 创建文件夹链接mklink /d "C:\Users\Admi ...
- Linux:history命令详解
Linux下History命令 主要用于显示历史指令记录内容, 下达历史纪录中的指令 . 语法 history [n] history [-c] history [-raw] histfiles ...
- Eclipse快捷键详细解析
android开发中常用的Eclipse快捷键详细解析 1.查看快捷键定义的地方 Window->Preferences->General->Keys. 2.更改启动页 在Andro ...
- MPAndroidChart Wiki(译文)~Part 3
13. 图例 默认情况下,所有的图表都支持图例并且会自动生成.给图表设置完数据之后,图例会被绘制出来.图例通常由多个条目组成,每个条目由标签形式/形状表示. 自动生成的图例包含的条目数取决于不同颜色的 ...
- jQuery插件实现表格隔行换色且感应鼠标高亮行变色
实现表格隔行换色,且感应鼠标行变色的方法有很多,在本文将为大家介绍的是使用jQuery插件来实现,具体如下 看代码: : css代码:
- Buildroot 使用默认配置
/******************************************************************************** * Buildroot 使用默认配置 ...
- Python源码分析(一)
最近想学习下Python的源码,希望写个系列博客,记录的同时督促自己学习. Python源码目录 从Python.org中下载源代码压缩包并解压,我下载的是Python2.7.12,解压后: 对于主要 ...
- 【剑指offer】二叉搜索树转双向链表,C++实现
原创博文,转载请注明出处! # 题目 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. 二叉树节点的定义 struct TreeNod ...
- Percona Xtrabackup 安装
1.安装Percona Xtrabackup YUM Repository --安装repository [root@manager ~]# yum install https://www.perco ...