1094. The Largest Generation (25)
来源:互联网 发布:观察者模式java代码 编辑:程序博客网 时间:2024/05/17 22:50
题目地址:http://www.patest.cn/contests/pat-a-practise/1094
/*1094. The Largest Generation (25)http://www.patest.cn/contests/pat-a-practise/1094*/#include <stdio.h>#include <stdlib.h>#include <math.h>#include <vector>#include <string>#include <unordered_map>#include <queue>#include <algorithm>#include <iostream>using namespace std;#define N 105int n , m;vector<int> v[N];int cont[N] ;unordered_map<int , int> um ;int maxNum ;int cengci ;void BFS(){ maxNum = 0; queue<int> que; que.push(1); cont[1] = 1; while( !que.empty() ) { int no = que.front(); que.pop(); um[cont[no]] ++; // 这里用map累加该层次的人数 if(um[cont[no]] > maxNum) { maxNum = um[cont[no]]; cengci = cont[no] ; } int len = v[no].size(); for(int i = 0 ; i < len ; i ++) { int no_next = v[no][i]; cont[no_next] = cont[no] + 1 ; que.push(no_next); } }}int main(){ //freopen("in.txt","r",stdin); scanf("%d%d",&n,&m); int i , j ; int id , k ,tmp; for(i = 0 ; i < m ; i++) { scanf("%d%d",&id,&k); for(j = 0 ;j < k ;j ++) { scanf("%d",&tmp) ; v[id].push_back(tmp); } } BFS(); printf("%d %d\n",maxNum , cengci); 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)
- 快速排序
- Objective-C之Mark
- Android:Layout_weight的深刻理解
- UVA 1149 Bin packing
- 设计模式系列--备忘录模式
- 1094. The Largest Generation (25)
- mongodb创建用户操作
- android 屏幕适配
- leetcode : Balanced Binary Tree
- ViewPager(页面滑动,加动态点,循环,加标题)
- JNI传递参数
- 把一个项目作为library加入其它项目出现莫名错误
- [概念]Base64编码
- 数据库 Sqlite数据库