当前位置:网站首页>Class Notes (7) (1) - #647. Find the root and the child (root)
Class Notes (7) (1) - #647. Find the root and the child (root)
2022-08-10 07:42:00 【xyc20120615】
Description
Given a tree, output the root root of the tree, the node with the most children max and its children.
Format
Input
The first line: n (number of nodes≤100), m (number of edges≤200).
The following m lines; each line has two nodes x and y, indicating that y is a child of x (x,y≤100).
Output
First line: tree root: root.
The second line: the node with the most children max.
The third line: the children of max.
Samples
Enter Data 1
8 74 14 21 31 52 62 72 8Output data 1
426 7 8Limitation
1s, 1024KiB for each test case.
Solution:
Although the standard answer is to use a binary tree, But!I prefer a binary tree!I'm going to use tag arrays!That's right!It's that simple array of tags!
Program:
#includeusing namespace std;int m,n,f,a[110],b[210],z[110],maxn;int main(){cin>>n>>m;for(int i=1;i<=m;i++)cin>>a[i]>>b[i];for(int i=1;i<=m;i++)z[b[i]]++;for(int i=1;i<=n;i++)if(!z[i])cout<=maxn)maxn=z[i];for(f=1;f<=n;f++){if(z[f]==maxn){cout< 边栏推荐
猜你喜欢
随机推荐
DGIOT三千万电表集抄压测
全连接神经网络结构图,神经网络示意图怎么画
Introduction to the delta method
pytest之parametrize参数化
第2章 变量和基本类型读书笔记
复杂AB实验
浅谈C语言实现冒泡排序
自动化测试框架Pytest(三)——自定义allure测试报告
Uni-app开发微信小程序使用本地图片做背景图
幂函数 指数函数 对数函数
[深入研究4G/5G/6G专题-56]: L3信令控制-5-无线承载管理
IDLE开发wordCount程序(第五弹)
nrm 使用详解
Summary of ctfshow SSTI knowledge points
Deep understanding of the array
进程管理(动态的)
A few lines of code can crash the system;
DGIOT 30 million meters set pressure reading
Go-Excelize API源码阅读(十一)—— GetActiveSheetIndex()
Relaxation class: the boss will martial arts, who also can not hold up against!The charm of six sigma training









