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 ...
随机推荐
- 模拟插队,出队,POJ(2259)
题目链接:http://poj.org/problem?id=2259 水题一个,就是要记录一下每个队列是否有人bool[i], #include <iostream> #include ...
- Mysql limit 优化,百万至千万级快速分页,--复合索引的引用并应用于轻量级框架
MySql 性能到底能有多高?用了php半年多,真正如此深入的去思考这个问题还是从前天开始.有过痛苦有过绝望,到现在充满信心!MySql 这个数据库绝对是适合dba级的高手去玩的,一般做一点1万篇新闻 ...
- python 爬取猫眼榜单100(二)--多个页面以及多进程
#!/usr/bin/env python # -*- coding: utf- -*- # @Author: Dang Kai # @Date: -- :: # @Last Modified tim ...
- app上线
不管第一次还是第二次APP上线都需要三样东西:开发者证书,appID,描述文件
- 通过redis实现的一个抢红包流程,仅做模拟【上】
建议结合下一篇一起看 下一篇 数据结构+基础设施 数据结构 这里通过spring-data-jpa+mysql实现DB部分的处理,其中有lombok的参与 @MappedSuperclass @Dat ...
- 转 IOS7开发错误收集
转自:http://blog.csdn.net/smallsky_keke/article/details/16117653 1. fatal error: file '/Applications/X ...
- oracle下表空间、用户创建以及用户授权流程
Oracle,表空间的建立.用户创建以及用户授权 主要是以下几步,挑选需要的指令即可: # 首先以scott用户作为sysdba登陆 conn scott/tiger as sysdba #创建用户 ...
- centos7 php7 安装php扩展
yum install php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 ...
- Redis 持久化操作
hash类型 类比:mysql数据库存储数据 持久化操作 以本身的数据以文件形式保存到硬盘中 手动快照持久化 i 备份机制(频率) vi redis.conf save 900 1 900s如果一个 ...
- NPOI导出Excel,添加图片和设置格式,添加条形码
先上代码 using grproLib; using System; using System.Collections.Generic; using System.Data; using System ...