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

#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. 安裝 PHP 時出現undefined reference to `libiconv_open’ 之類的錯誤訊息

    在安裝 PHP 到系統中時要是發生「undefined reference to `libiconv_open'」之類的錯誤訊息,那表示在「./configure 」沒抓好一些環境變數值.錯誤發生點在 ...

  2. 创建 XXXXXXXX 的配置节处理程序时出错: 请求失败

    今天碰到这个错误,之前的程序在测试的时候都没有问题,同样的程序打包通过QQ传给其他人,在XP下测试也没有问题,我的Win7系统从QQ信箱下载压缩包,解压之后执行程序就会出问题,本来还是考虑自己程序是不 ...

  3. 通过redis实现的一个抢红包流程,仅做模拟【上】

    建议结合下一篇一起看 下一篇 数据结构+基础设施 数据结构 这里通过spring-data-jpa+mysql实现DB部分的处理,其中有lombok的参与 @MappedSuperclass @Dat ...

  4. 3.Netty的粘包、拆包(二)

    Netty提供的TCP数据拆包.粘包解决方案 1.前言 关于TCP的数据拆包.粘包的介绍,我在上一篇文章里面已经有过介绍. 想要了解一下的,请点击这里 Chick Here! 今天我们要讲解的是Net ...

  5. BZOJ1008: [HNOI2008]越狱(组合数)

    题目描述 监狱有连续编号为 1…N1…N 的 NN 个房间,每个房间关押一个犯人,有 MM 种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱. ...

  6. mysql 数据库设计规范

    MySQL数据库设计规范 目录 1. 规范背景与目的 2. 设计规范 2.1 数据库设计 2.1.1 库名 2.1.2 表结构 2.1.3 列数据类型优化 2.1.4 索引设计 2.1.5 分库分表. ...

  7. javaScript的闭包 js变量作用域

    js的闭包 js的变量作用域: var a=90; //定义一个全局变量 function test(){ a=123; //使用外层的 a变量 } test(); document.write(&q ...

  8. python3 练习题100例 (十八)托儿所问题

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- """练习十八:某托儿所有大.中.小三个班级,其儿童月龄分别用如下 三个列表 ...

  9. Aizu:2170-Marked Ancestor

    Marked Ancestor Time limit 8000 ms Memory limit 131072 kB Problem Description You are given a tree T ...

  10. 7 Django的模板层

    你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python代码之中. def current_datetime(request): now = datet ...