当前位置:网站首页>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;
}边栏推荐
- Number of uniform strings of leetcode simple problem
- Market status and development prospect prediction of the global fire extinguisher industry in 2022
- Learn to use the idea breakpoint debugging tool
- Number of 1 in binary (simple difficulty)
- The least operation of leetcode simple problem makes the array increment
- [research materials] 2022q1 game preferred casual game distribution circular - Download attached
- 移动端——uniapp开发记录(公共请求request封装)
- Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)
- Oracle SQL table data loss
- Shell script -- condition judgment
猜你喜欢

Learn to use the idea breakpoint debugging tool

Thesis reading_ Tsinghua Ernie

Preparation for school and professional cognition

Games101 Lesson 9 shading 3 Notes
![[XSS bypass - protection strategy] understand the protection strategy and better bypass](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[XSS bypass - protection strategy] understand the protection strategy and better bypass

Oracle SQL table data loss

"Niuke brush Verilog" part II Verilog advanced challenge

逆袭大学生的职业规划

Flutter monitors volume to realize waveform visualization of audio

Leetcode simple question: check whether the array is sorted and rotated
随机推荐
Actual combat 8051 drives 8-bit nixie tube
Valentine's day limited withdrawal guide: for one in 200 million of you
Shuttle + Alluxio 加速内存Shuffle起飞
Learn to use the idea breakpoint debugging tool
1111 online map (30 points)
Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
[Yu Yue education] basic reference materials of interchangeability and measurement technology of Zhongyuan Institute of Technology
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
MySQL winter vacation self-study 2022 12 (3)
【SQL注入】联合查询(最简单的注入方法)
What is UUID
Notes | numpy-09 Broadcast
Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
Leetcode simple question: check whether the array is sorted and rotated
论文阅读_清华ERNIE
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
1118 birds in forest (25 points)
Problems encountered in fuzzy query of SQL statements
[research materials] annual report of China's pension market in 2021 - Download attached
Silent authorization login and registration of wechat applet