求结点最多的一层 输出该层的结点个数以及层号

#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 分)(树的遍历)的更多相关文章

  1. PTA甲级1094 The Largest Generation (25分)

    PTA甲级1094 The Largest Generation (25分) A family hierarchy is usually presented by a pedigree tree wh ...

  2. 【PAT甲级】1094 The Largest Generation (25 分)(DFS)

    题意: 输入两个正整数N和M(N<100,M<N),表示结点数量和有孩子结点的结点数量,输出拥有结点最多的层的结点数量和层号(根节点为01,层数为1,层号向下递增). AAAAAccept ...

  3. 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 ...

  4. 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 ...

  5. 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)

    题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...

  6. 1094. The Largest Generation (25)

    A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level bel ...

  7. PAT (Advanced Level) 1094. The Largest Generation (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  8. PAT练习——1094 The Largest Generation (25 point(s))

    题目如下: #include<iostream> #include<vector> #include<algorithm> using namespace std; ...

  9. PAT甲级——1094 The Largest Generation (树的遍历)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/93311728 1094 The Largest Generati ...

  10. pat1094. The Largest Generation (25)

    1094. The Largest Generation (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

随机推荐

  1. caffe RandomOrderChannels

    就是将rgb图的3个channel随机打乱顺序,给定一个概率值是否执行这个操作,v系列模型的概率一般都设置的为0 void RandomOrderChannels(const cv::Mat& ...

  2. svn update 时总是提示 Password for '默认密钥' GNOME keyring: 输入密码

    执行svn update 时 总是提示输入密码. $ cd ~/.gnome2/keyrings/ $ ls $ rm 默认密钥.keyring

  3. cudaMemcpy2D介绍

    cudaMemcpy2D( d_A, // 目的指针 d_pitch, // 目的pitch bmp1, // 源指针 sizeof(int)*2, // 源数据pitch sizeof(int)*2 ...

  4. 分布式系统session一致性问题

    一.引言 1.什么是session Session 是服务器用来保存用户操作的一系列会话信息,由Web容器进行管理.最常见的,会把用户的登录信息.用户信息存储在 session 中,以保持登录状态. ...

  5. python 生成器与迭代器(yield 用法)

    背景 首先,我不会解释这两个名词,我看过很多遍解释,可还是看不懂,还是直接看使用情景吧. 我们以佩波拉契数列为例,当我们不知道迭代器的情况下,我们写出来的代码可能是这样子的: '''这种方式计算fib ...

  6. 关于js的严格模式

    最近在看你不知道js,补充自己的js基础,加深理解.在读的过程中写点笔记. 严格模式下与非严格模式的区别 . 严格模式是es5新增的,es6是默认为严格模式的!js默认状态下是非严格模式的!   一般 ...

  7. 【jQuery】input框输入手机号自动填充空格

    <input type="tel" id="tel"> $("#tel").keyup(function(){ _self = ...

  8. 16.2,docker网络

      Docker 允许通过外部访问容器或容器互联的方式来提供网络服务. 端口映射允许外部访问容器 --link 容器互联 容器桥接网络 .通过--link容器通信,给test2添加一个hosts解析记 ...

  9. ZOJ 3329 Problem Set (期望dp)

    One Person Game There is a very simple and interesting one-person game. You have 3 dice, namely Die1 ...

  10. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable

    编译的时候出现这个,我从svn download下来的代码,运行就报这个错. 当时我还无知的大吼,怎么可能没有配置java_home, 运行了java -version 都显示出来1.8了. 后来,让 ...