当前位置:网站首页>上课笔记(7)(1)——#647. 找树根和孩子(root)
上课笔记(7)(1)——#647. 找树根和孩子(root)
2022-08-10 07:31:00 【xyc20120615】
Description
给定一棵树,输出树的根 root,孩子最多的结点 max 以及他的孩子。
Format
Input
第一行:n(结点数≤100),m(边数≤200)。
以下 m 行;每行两个结点 x 和 y,表示 y 是 x 的孩子(x,y≤100)。
Outpu
第一行:树根:root。
第二行:孩子最多的结点 max。
第三行:max 的孩子。
Samples
输入数据 1
8 7
4 1
4 2
1 3
1 5
2 6
2 7
2 8
输出数据 1
4
2
6 7 8
Limitation
1s, 1024KiB for each test case.
题解:
虽然标准答法是用二叉树,但是!我偏不用二叉树!我就要用标记数组!没错!就是那个简单到爆的标记数组!
程序:
#include<bits/stdc++.h>
using 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<<i<<endl;
memset(z,0,sizeof(z));
for(int i=1;i<=m;i++)
z[a[i]]++;
for(int i=1;i<=n;i++)
if(z[i]>=maxn)
maxn=z[i];
for(f=1;f<=n;f++){
if(z[f]==maxn){
cout<<f<<endl;
break;
}
}
for(int i=1;i<=m;i++)
if(a[i]==f)
cout<<b[i]<<" ";
}
边栏推荐
- PLSQL学习第一天
- May I ask why sqlserver cdc will report this error one day after the task is started, obviously cdc has been opened.
- What is an MQTT gateway?What is the difference with traditional DTU?
- 探索神经网络架构教程视频,设计神经网络的步骤
- 90. (cesium house) cesium height monitoring events
- 深入理解LTE网络的CDRX
- Elementary Structure
- S0:12345:respawn:/bin/start_getty 115200 ttyS0 vt102
- 英国国家卫生服务遭受攻击,系统出现大面积故障
- Discussion on Chinese Fuzzy Retrieval in Databases
猜你喜欢
颜色选择器的使用
PLSQL学习第一天
浅谈C语言整型数据的存储
每日一题,数组字符串的匹配问题
神经网络样本太少怎么办,神经网络训练样本太少
MVCC详解
张驰课堂:老板会武术,谁也挡不住!六西格玛培训的魅力
WooCommerce 安装和 rest api 使用
What is an MQTT gateway?What is the difference with traditional DTU?
Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
随机推荐
幂函数 指数函数 对数函数
winget包管理器
金融证券 初级 招股书 要求 黑话1刷数 黑话2底稿 黑话3董监高
2022 Henan Mengxin League (fifth) game: University of Information Engineering H - Xiao Ming drinking milk tea
时序动作定位 | ACGNet:弱监督时序动作定位的动作补充图网络(AAAI 2022)
About MongoDb query Decimal128 to BigDecimal problem
3. Transactions [mysql advanced]
May I ask why sqlserver cdc will report this error one day after the task is started, obviously cdc has been opened.
u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
自组织是管理者和成员的双向奔赴
761. Special Binary Sequences
DGIOT 30 million meters set pressure reading
placeholder 1
Uni applet Tencent map polygon background transparency
如何正确理解线程机制中常见的I/O模型,各自主要用来解决什么问题?
WooCommerce 安装和 rest api 使用
uni 小程序腾讯地图polygon背景透明度
[Reinforcement Learning] "Easy RL" - Q-learning - CliffWalking (cliff walking) code interpretation
模糊查询除了like+ % 还能用什么方式
DGIOT支持工业设备租赁以及远程管控