当前位置:网站首页>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;
}边栏推荐
- Market status and development prospect prediction of global fermentation acid industry in 2022
- 1114 family property (25 points)
- Objects. Requirenonnull method description
- Wechat applet waterfall flow and pull up to the bottom
- [set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
- [clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree
- [tools run SQL blind note]
- Learn to use the idea breakpoint debugging tool
- 论文阅读_中文NLP_ELECTRA
- Leetcode simple problem delete an element to strictly increment the array
猜你喜欢

Thesis reading_ Chinese NLP_ ELECTRA

带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...

Silent authorization login and registration of wechat applet

Cross platform plug-in flutter for displaying local notifications_ local_ notifications

移动端——uniapp开发记录(公共请求request封装)

5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip

Games101 Lesson 9 shading 3 Notes

Source insight garbled code solution

Mobile terminal - uniapp development record (public request encapsulation)

The least operation of leetcode simple problem makes the array increment
随机推荐
论文阅读_中文NLP_ELECTRA
Wechat applet distance and map
Market status and development prospect prediction of global fermentation acid industry in 2022
Mobile terminal - uniapp development record (public request encapsulation)
2022-02-11 daily clock in: problem fine brush
112 stucked keyboard (20 points)
Keepalived热备与HAProxy
@RequestMapping
STM32 reverse entry
Shuttle + alluxio accelerated memory shuffle take-off
LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
Learning record of arouter principle
第十九届浙江省 I. Barbecue
【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
Three representations of signed numbers: original code, inverse code and complement code
Learn to use the idea breakpoint debugging tool
Unity tool Luban learning notes 1
Leetcode simple question: check whether the array is sorted and rotated
MySQL winter vacation self-study 2022 12 (3)
Kept hot standby and haproxy