当前位置:网站首页>1094 the largest generation (25 points)
1094 the largest generation (25 points)
2022-07-03 04:55:00 【vs5】
The main idea of the topic : Give a genealogical tree , The same layer is a generation , Ask for the largest generation , And which floor .
bfs,dfs Fine
#include <iostream>
#include <queue>
#include <unordered_map>
using namespace std;
vector<int>e[200];
unordered_map<int,int>mp,root;
int u,h,s;
void bfs()
{
queue<pair<int,int>>que;
que.push({u,1});
while(que.size())
{
auto t = que.front();que.pop();
int v = t.first,c = t.second;
mp[c] ++;
for(auto it : e[v])
{
que.push({it,c + 1});
}
}
}
int main()
{
int n,m;
cin >> n >> m;
while(m --)
{
int fa,cs,ch;
cin >> fa >> cs;
for(int i = 0; i < cs; i ++)
{
cin >> ch;
root[ch] = 1;
e[fa] .push_back(ch);
}
}
for(int i = 1; i <= n; i ++) if(!root.count(i)) u = i;
bfs();
for(auto it : mp)
{
if(it.second > s) s = it.second,h = it.first;
}
cout << s << ' ' << h << endl;
return 0;
}
边栏推荐
- Silent authorization login and registration of wechat applet
- 联发科技2023届提前批IC笔试(题目)
- Current market situation and development prospect forecast of global UV sensitive resin 3D printer industry in 2022
- Preparation for school and professional cognition
- Wechat applet distance and map
- Market status and development prospect prediction of the global fire alarm sensor industry in 2022
- The 19th Zhejiang I. barbecue
- Truncated sentences of leetcode simple questions
- I stepped on a foundation pit today
- Leetcode simple question: check whether the string is an array prefix
猜你喜欢
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Leetcode simple question: check whether the array is sorted and rotated
《牛客刷verilog》Part II Verilog进阶挑战
I stepped on a foundation pit today
Basic use of Metasploit penetration testing framework
【XSS绕过-防护策略】理解防护策略,更好的绕过
Mobile terminal - uniapp development record (public request encapsulation)
【工具跑SQL盲注】
"Niuke brush Verilog" part II Verilog advanced challenge
论文阅读_清华ERNIE
随机推荐
Shell script Basics - basic grammar knowledge
50 practical applications of R language (36) - data visualization from basic to advanced
Truncated sentences of leetcode simple questions
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
《牛客刷verilog》Part II Verilog进阶挑战
Valentine's day limited withdrawal guide: for one in 200 million of you
Flutter monitors volume to realize waveform visualization of audio
MySQL winter vacation self-study 2022 12 (3)
1118 birds in forest (25 points)
Career planning of counter attacking College Students
Uipath practice (08) - selector
带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
Leetcode simple problem delete an element to strictly increment the array
Market status and development prospect prediction of the global fire extinguisher industry in 2022
Notes | numpy-08 Advanced index
Market status and development prospect prediction of global neutral silicone sealant industry in 2022
Preparation for school and professional cognition
Shell script -- condition judgment