当前位置:网站首页>上课笔记(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]<<" ";
}
边栏推荐
- 3.1-3.3 读书笔记
- Based on STC8G2K64S4 single-chip microcomputer to display analog photosensitive analog value through OLED screen
- I would like to ask you guys, when FLink SQL reads the source, specify the time field of the watermark. If the specified field is in the grid
- 全连接神经网络结构图,神经网络示意图怎么画
- 物联网时代下的网络整合推广外包精准化效果-深圳双赢世讯
- 时序动作定位 | ASM-Loc:弱监督时序动作定位的动作感知片段建模(CVPR 2022)
- 幂函数 指数函数 对数函数
- 深入理解LTE网络的CDRX
- Elementary Structure
- 大佬,oracle单表增量同步时候源库服务器额外占用内存近2g,这不正常吧
猜你喜欢
NPU架构与算力分析
机器人控制器编程实践指导书旧版-实践一 LED灯(数字量)
一文2600字手把手教你编写性能测试用例
Chapter 12 Other Database Tuning Strategies [2. Index and Tuning] [MySQL Advanced]
Using the color picker
【愚公系列】2022年08月 Go教学课程 034-接口和多态
COLMAP+OpenMVS realizes 3D reconstruction mesh model of objects
模糊查询除了like+ % 还能用什么方式
Grammar Basics (Judgment Statements)
ATH10 sensor reads temperature and humidity
随机推荐
搭建 risc-v 编译环境
什么是长轮询
Everyone, the default configuration of oracle cdc occasionally takes 30 seconds to capture data. How to optimize this?
MySQL's InnoDB engine (6)
神经网络样本太少怎么办,神经网络训练样本太少
941 · Sliding Puzzles
PLSQL学习第一天
Using the color picker
Fiddler(八) - 抓取手机APP的流量-插件Fiddler Orchestra Beta安装&配置
手把手教你进行Mysql查询操作
机器人控制器编程实践指导书旧版-实践一 LED灯(数字量)
【MySQL】使用MySQL Workbench软件新建表
34. Talk about why you want to split the database?What methods are there?
幂函数 指数函数 对数函数
navicat for mysql 连接时报错:1251-Client does not support authentication protocol requested by server
【Event Preview on August 9】Prometheus Summit
.NET-7.WPF learning experience summary
u-boot ERROR: Failed to allocate 0x5c6f bytes below 0x17ffffff.Failed using fdt_high value
如何设计神经网络结构,神经网络设计与实现
复杂AB实验