1094 The Largest Generation (25 分)(树的遍历)
求结点最多的一层 输出该层的结点个数以及层号
#include<bits/stdc++.h> using namespace std;
vector<int>vec[];
map<int,int>mp;
void dfs(int v,int step)
{
mp[step]++;
if(vec[v].size()==){
return;
}
for(int i=;i<vec[v].size();i++){
dfs(vec[v][i],step+);
}
}
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=;i<m;i++){
int id;
int k;
scanf("%d %d",&id,&k);
while(k--){
int x;
scanf("%d",&x);
vec[id].push_back(x);
}
}
dfs(,);
multimap<int,int,greater<int> >M;
for(auto it:mp){
M.insert(pair<int,int>(it.second,it.first));
}
auto it=M.begin();
cout<<it->first<<" "<<it->second<<endl; return ;
}
1094 The Largest Generation (25 分)(树的遍历)的更多相关文章
- PTA甲级1094 The Largest Generation (25分)
PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...
- 【PAT甲级】1094 The Largest Generation (25 分)(DFS)
题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...
- 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 ...
- 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 ...
- 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)
题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...
- 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 (Advanced Level) 1094. The Largest Generation (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT练习——1094 The Largest Generation (25 point(s))
题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...
- PAT甲级——1094 The Largest Generation (树的遍历)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...
- pat1094. The Largest Generation (25)
1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
随机推荐
- 20145238-荆玉茗 《Java程序设计》第3周学习总结
20145238 <Java程序设计>第3周学习总结 教材学习内容总结 一.定义类: ·类定义时使用class关键字 ·如果要将x绑定到新建的对象上,可以使用"="制定 ...
- 系统运行时间悬浮框(demo)
此项目基于.net framework 4.0 思路: 拖一个定时器控件,每秒执行一次,调用函数查询当前运行时间并更新到label控件. private void Form1_Load(object ...
- ILSVRC2014检测总结
ILSVRC 2014结束一段时间了.从下面的表格来看,基本都是RCNN的路子,但是这些牛队都做了改进.自己和人家比差的太远啊,努力. team results Spotlights and impr ...
- django中的forms组件(权限信息校验,增删改查)
1.用处 1.用户请求数据验证 2.自动生成错误信息 3.打包用户提交的正确信息 4.如果其中有一个错误了,其他的正确,则保留上次输入的内容 5.自动创建input标签并可以设置样式 6.基于form ...
- 调整JVM占用内存空间方法
JVM默认占用空间为64M 调整方法如下图 在虚拟机参数中调整为80M 调试可以用 Byte[] arr=new Byte[1024*1024*64];
- Python 统计不同url svn代码变更数
#!/bin/bash/python # -*-coding:utf-8-*- #svn统计不同url代码行数变更脚本,过滤空行,不过滤注释. import subprocess,os,sys,tim ...
- Lucene检索提高性能的几个方式
1.采用最新版本的Lucene 2.索引文件存储采用本地文件系统,如果需要挂载远程系统,请采用 readonly方式. 3.当然采用更好的硬件,更高I/O的磁盘 4.提高OS 缓存,调整参数 5.提高 ...
- mariadb源码编译安装及多实例
准备文件源文件/app/mariadb-10.2.12.tar.gz cd /app/ tar xf mariadb-10.2.12.tar.gz cd mariadb-10.2.12 mkdir ...
- Mybatis基础入门学习
Mybatis基础入门学习 mybatis架构分析 搭建测试mybatis架构 )下载并导入mybatis3.2.7.jar(架构),mysql-connector-java-5.1.7-bin.ja ...
- 【MYSQL笔记1】mysql的基础知识
首先进去mysql.打开电脑命令提示符(cmd):输入mysql -uroot -p 代表的意思是使用ruser使用者root的方式,打开mysql,-p代表password,如果有的话,回车之后 ...