1094. The Largest Generation 解析
来源:互联网 发布:超级老师软件 编辑:程序博客网 时间:2024/06/04 19:43
求一大家子哪一辈的人数最多。
直接层序遍历,然后统计。
#include <iostream>#include <algorithm>#include <cstring>#include <climits>#include <string>#include <vector>#include <map>#include <set>#include <queue>#include <stack>#define MAX 110using namespace std;int n,m;struct node{int level;vector <int> next;};node t[MAX];int LevelCount[MAX];int maxSize = 1;int maxLevel = 1;void LevelOrder(int root){queue <int> q;t[root].level = 1;q.push(root);LevelCount[t[root].level]++;while(!q.empty()){int top = q.front();q.pop();for(int i = 0 ; i < t[top].next.size();i++){int cno = t[top].next[i];t[cno].level = t[top].level + 1;LevelCount[t[cno].level]++;if(LevelCount[t[cno].level] > maxSize){maxSize = LevelCount[t[cno].level];maxLevel = t[cno].level;}q.push(cno);}}}int main(){cin >> n >> m;int no,size,cno;for(int i = 0 ;i < m ; i++){cin >> no >> size;for(int j = 0 ; j < size ;j++){cin >> cno;t[no].next.push_back(cno);}}LevelOrder(1);cout << maxSize << " " << maxLevel << endl;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
- 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)
- 用BlueScreenView分析蓝屏故障文件MEMORY.DMP
- H5 基础选择器
- 使用ES-Hadoop插件结合spark向es插入数据
- 样搭建一个便于优化的网站思路
- zoj3879 模拟
- 1094. The Largest Generation 解析
- ArcGIS10.2下载安装 License Manager、ArcGIS Desktop、ArcGIS Server软件下载及破解
- Lua面向对象的实现方法
- 【小白笔记】目标跟踪DSST改进版fDSST算法代码分析
- GIT命令
- 在tomcat服务器中部署php
- 可拖拽ListView
- 1095. Cars on Campus 解析
- Centos yum安装软件报软件包下载失败