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> ...
随机推荐
- 第9课:备份mysql数据库、重写父类、unittest框架、多线程
1. 写代码备份mysql数据库: 1)Linux下,备份mysql数据库,在shell下执行命令:mysqldump -uroot -p123456 -A >db_bak.sql即可 impo ...
- 利用Appium Python测试爱壁纸的登录和设置壁纸
设置壁纸: #coding:utf-8 #Import the common package import os import unittest from appium import webdrive ...
- 20165202 预备作业3 Linux安装及学习
一.虚拟机安装 娄老师的<基于VirtualBox安装Ubuntu图文教程>对于安装过程的介绍很易懂,但在安装过程中还是遇到了一些问题 Q1:安装教程中下载地址的VM提示安装包损坏 解决办 ...
- JSP和JS的区别
从本科毕业设计开始就一直困扰我,jsp和js这两者的区别,一直处于迷糊状态,也没有搞清楚.今天就简单的介绍下两者的区别. 1.JSP全称是java server page JS全称是javaSc ...
- 3PC
3PC,是Three-Phase Commit的缩写,即三阶段提交,是2PC的改进版,其二阶段提交协议的"提交事务请求"过程一分为二,形成了由CanCommit,PreCommit ...
- SSH 首次登录太慢问题
这两天在使用 Docker 做测试,发现新建的容器在首次 ssh 登录的时候经常超时,我们简单将超时时间设置成60秒,但仍然会偶尔超时.所以简单延迟超时时间此路不通. 于是想到是否可以通过修改 ssh ...
- ss-libev 源码解析udp篇 (4)
本篇分析remote_recv_cb,这是整个udp转发的反方向,即读取从后端发送过来的数据再发送给前端.对于ss-server,读取到的数据是目标地址的udp服务器发送回来的响应数据,ss-serv ...
- MPAndroidChart Wiki(译文)~Part 1
1. 基础入门 1.1 添加依赖 Gradle 工程添加依赖 (推荐使用) 项目级build.gradle中添加: allprojects { repositories { maven { url & ...
- js 由快到慢的执行
let t=0; for(var i=0;i<len;i++){ (function (t) { $timeout(function(){ console.log(t); },t); })(t) ...
- python重要模块之subprocess模块
python重要模块之subprocess模块 我们经常要通过python去执行系统的命令或者脚本,系统的shell命令是独立于你的python进程之外的,每执行一条命令,就相当于发起了一个新的进程, ...