1094. The Largest Generation (25)
来源:互联网 发布:毕业生自我鉴定知乎 编辑:程序博客网 时间:2024/06/08 17:58
#include<cstdio>#include<queue>#include<vector>using namespace std;#define maxn 200struct node{ int data; int level; vector<int> child;}tree[maxn];int head = 1,N,K,max_level=1,max_cnt=0;int father,n;int has[maxn]={0};void level_order(int head){ queue<int> qu; qu.push(head); tree[head].level = 1; while (!qu.empty()) { int front = qu.front(); qu.pop(); has[tree[front].level]++; for(int i=0; i<tree[front].child.size(); i++) { int child = tree[front].child[i]; tree[child].level = tree[front].level+1; qu.push(child); } }}int main(){ //获取数据,并构造树 scanf("%d%d",&N,&K); for(int i=0; i<K; i++) { scanf("%d%d",&father,&n); for(int j=0; j<n; j++) { int x; scanf("%d",&x); tree[father].child.push_back(x); } } //层次遍历,并计算最大宽度 level_order(head); //输出结果 for(int i=0; i<maxn; i++) { if(has[i]>max_cnt) { max_cnt = has[i]; max_level = i; } } printf("%d %d",max_cnt,max_level); 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)
- POSIX(Portable Operating System Interface )信号处理
- 1092. To Buy or Not to Buy (20)
- 1.3props与state
- Windows每月更新补丁离线安装包下载
- 仙人掌相关问题的处理方法(未完待续)
- 1094. The Largest Generation (25)
- Gson的使用
- Python的基础性东西学习
- Linux开发基础:Shell编程入门(一)
- int与string的相互转换
- 1099. Build A Binary Search Tree (30)
- 1096. Consecutive Factors (20)
- HDU1016:Prime Ring Problem(DFS)
- Oracle 12C 新特性之表分区或子分区的在线迁移