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 ...
随机推荐
- caffe安装中opencv的各种库问题
提示有些库 high**** opencv的问题,好像是这几个库版本冲突,不要用anaconda里的lib库,用系统的库就行了,删掉或者从新链接过去.
- mac系统的几种u盘启动制作方式
先拿一个U盘,格式化好(guid分区表之类的选项弄好) 1.通过终端制作: 1>下载好自己要安装的系统镜像,最新的在App Store上下,以前的可以去pc 苹果等地方下载 2>在终端输入 ...
- java后台导出pdf
新页面打开wpf @RequestMapping("/showPdf") public String getpic( HttpServletRequest request, Htt ...
- java基础 序列化反序列化流 实现Serializable 接口 自动装载序列号到对象文本文件如修改不能反序列化对象文本,除非自定义long型常量 打印流
package com.swift.baseKnowledge; import java.io.File; import java.io.FileInputStream; import java.io ...
- v-for的简单实现
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 在ubuntu中docker的简单使用(一)
>>docker version 当运行docker version 命令出现Cannot connect to Docker daemon. Is the docker daemon r ...
- 谈谈两种标准库类型---string和vector
两种最重要的标准库---string和vector string和vector是两种最重要的标准库类型,string表示可变长的字符序列,vector存放的是某种给定类型对象的可变长序列. 一.标准库 ...
- 1816: [Cqoi2010]扑克牌
Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 2737 Solved: 1082[Submit][Status][Discuss] Descripti ...
- spring-bean(注解方式-管理及依赖注入)
Bean管理(注解方式) 1.添加注解的依赖包:Spring-aop.jar 2.配置spring的XML文件的引入(查官方源码) 3.开启注解的扫描 <context:component-sc ...
- JQuery实现子级选择器
效果图如下: HTML代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...