1094. The Largest Generation
来源:互联网 发布:centos 7 更改ftp目录 编辑:程序博客网 时间:2024/06/05 06:24
A family hierarchy is usually presented by a pedigree tree where all the nodes on the same level belong to the same generation. Your task is to find the generation with the largest population.
Input Specification:
Each input file contains one test case. Each case starts with two positive integers N (<100) which is the total number of family members in the tree (and hence assume that all the members are numbered from 01 to N), and M (
#include<cstdio>#include<algorithm>#include<vector>#include<cstring>#include<queue>using namespace std;const int maxn=105;int n,m,num=1,level=1;vector<int>v[maxn];void solve(){ queue<int>q; q.push(1); int cnt=1,leftNum=1,curNum=0,temp,len; while(!q.empty()){ temp=q.front(); q.pop(); leftNum--; len=v[temp].size(); for(int i=0;i<len;i++){ q.push(v[temp][i]); curNum++; } if(leftNum==0){ leftNum=curNum; cnt++; if(curNum>num){ num=curNum; level=cnt; } curNum=0; } }}int main(){ //freopen("in.txt","r",stdin); int cnt,fa,child; scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ scanf("%d%d",&fa,&cnt); for(int i=0;i<cnt;i++){ scanf("%d",&child); v[fa].push_back(child); } } solve(); printf("%d %d\n",num,level); return 0;}
0 0
- 1094.The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- Linux-信号机制详解(二)
- Oracle【BC】
- apicloud图片缓存的使用和查看清除缓存
- JavaScript闭包的理解
- 补: Codeforces Round #355 (Div. 2)
- 1094. The Largest Generation
- 1-INTRODUCTION
- python2.7+opencv3.1 打开摄像头
- 367. Valid Perfect Square
- MYSQL索引:对聚簇索引和非聚簇索引的认识
- Spring初级学习!!!
- System V和Posix消息队列的差别
- Spark DataFrame中的join类型
- Devstack 多节点自动化部署