1094. The Largest Generation (25)
来源:互联网 发布:学通网络ps教程 编辑:程序博客网 时间:2024/05/17 09:29
走一遍BFS,计算每一层的孩子数目,同时跟踪最大值
#include <iostream>#include <cstdio>#include <vector>#include <queue>using namespace std;vector<vector<int>> tree;int main(){int n,m;scanf("%d%d", &n, &m);tree.resize(n+1, vector<int>());for(int i = 0; i < m; ++i){int id, k, child;scanf("%d%d", &id, &k);for(int j = 0; j < k; ++j){scanf("%d", &child);tree[id].push_back(child);}}int maxNum = 0, maxLevel = 0;vector<int> hist(101, 0);queue<pair<int,int>> Q;Q.push({1, 1});while(!Q.empty()){auto p = Q.front(); Q.pop();int id = p.first, level = p.second;hist[level]++;if(hist[level] > maxNum){maxNum = hist[level];maxLevel = level;}for(auto& c : tree[id]){Q.push({c, level+1});}}printf("%d %d", maxNum, maxLevel);return 0;}
0 0
- 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)
- 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)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- Ubuntu 14.04下Openface的环境搭建
- HDU 1527 取石子游戏 威尔夫博弈
- Linux中随手可得的测试、调试、性能检验工具
- JAVA:string中的copyValueOf方法
- Oracle DBlink方式
- 1094. The Largest Generation (25)
- 百度坐标与地理位相关接口
- str_replace
- okhttp的简单封装
- 线程池的那些事儿
- Maven打包时加入依赖包及加入本地依赖包
- CSS3动画属性animation的基本用法
- [珠玑之椟]浅谈代码正确性:循环不变式、断言、debug
- HDU5605——geometr