1094. The Largest Generation (25) PAT甲级
来源:互联网 发布:淘宝联盟有什么用 编辑:程序博客网 时间:2024/06/05 15:57
传送门
#include<stdio.h>#include<vector>#include<queue>#define MAX_N 110using namespace std;struct Node{ int level; vector<int> child;}node[MAX_N];int gene[MAX_N];int n;int m;void bfs(int root,int level){ node[root].level=1; //gene[level]++; queue<int> q; q.push(root); while(!q.empty()){ int p=q.front(); q.pop(); gene[node[p].level]++; for(int i=0;i<node[p].child.size();i++){ node[node[p].child[i]].level=node[p].level+1; q.push(node[p].child[i]); } }}int main(){ int id,k; int child; scanf("%d%d",&n,&m); for(int i=0;i<m;i++){ scanf("%d%d",&id,&k); for(int j=0;j<k;j++){ scanf("%d",&child); node[id].child.push_back(child); } } bfs(1,1); int maxLevel=0,max=0; for(int i=1;i<MAX_N;i++){ if(gene[i]>max){ max=gene[i]; maxLevel=i; } } printf("%d %d",max,maxLevel);}
0 0
- 1094. The Largest Generation (25) PAT甲级
- PAT 甲级 1094. The Largest Generation (25)
- PAT甲级 The Largest Generation (25)
- [转]PAT甲级练习1094. The Largest Generation (25)
- PAT甲级真题及训练集(25)--1094. The Largest Generation (25)
- 1094. The Largest Generation (25)-PAT甲级真题(bfs,dfs,树的遍历)
- PAT A 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- 【PAT】1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- pat-1094. The Largest Generation (25)
- PAT(A) - 1094. The Largest Generation (25)
- PAT 1094. The Largest Generation (25)
- PAT-A-1094. The Largest Generation (25)
- pat-a 1094. The Largest Generation (25)
- PAT A 1094. The Largest Generation (25)
- c++中new在子函数中的使用
- 如何调优JVM - 优化Java虚拟机(大全+实例)
- bzoj1003 [ZJOI2006]物流运输
- 彻底解决Spring mvc中文乱码问题
- ArrayList-LinkedList-Vector
- 1094. The Largest Generation (25) PAT甲级
- 在同一个mysql服务器上不同的数据库之间复制数据表
- Ubuntu 中安装opencv2411
- 1030. Travel Plan (30)
- Qt之QTableWidget详解
- 无限分类,列表页数据展现
- hadoop 安装常见的异常
- Java泛型
- Hibernate学习笔记(三)