当前位置:网站首页>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;
}边栏推荐
- Day 51 - tree problem
- Thesis reading_ Chinese NLP_ ELECTRA
- Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution
- Market status and development prospect forecast of global heat curing adhesive industry in 2022
- Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
- Objects. Requirenonnull method description
- Triangular rasterization
- 并发操作-内存交互操作
- String matching: find a substring in a string
- Current market situation and development prospect forecast of the global fire boots industry in 2022
猜你喜欢

Introduction to JVM principle

First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT

Leetcode simple problem delete an element to strictly increment the array

Career planning of counter attacking College Students

论文阅读_中文医疗模型_ eHealth

Source insight garbled code solution

The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge

I stepped on a foundation pit today

Web security - CSRF (token)
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached
随机推荐
Objects. Requirenonnull method description
Small sample target detection network with attention RPN and multi relationship detector (provide source code, data and download)
Introduction to JVM principle
[SQL injection point] location and judgment of the injection point
Leetcode simple question: check whether the string is an array prefix
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
1119 pre- and post order traversals (30 points)
UiPath实战(08) - 选取器(Selector)
LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
Career planning of counter attacking College Students
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
I stepped on a foundation pit today
JDBC database operation
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Day 51 - tree problem
[set theory] binary relation (example of binary relation operation | example of inverse operation | example of composite operation | example of limiting operation | example of image operation)
Kept hot standby and haproxy
[research materials] 2021 China's game industry brand report - Download attached
[BMZCTF-pwn] 18-RCTF-2017-Recho
The 19th Zhejiang I. barbecue