当前位置:网站首页>1110 complete binary tree (25 points)
1110 complete binary tree (25 points)
2022-07-03 04:55:00 【vs5】
The main idea of the topic : Given the left and right children of each node , Judge whether this tree is a complete binary tree
If the maximum node number is equal to the number of nodes, then it is a complete binary tree
#include <iostream>
#include <queue>
#include <unordered_map>
using namespace std;
int n,last,res;
struct Eg
{
string l,r;
}e[100];
unordered_map<int,int>mp;
void dfs(int u,int idx)
{
if(idx > last)
{
last = idx;
res = u;
}
if(e[u].l != "-") dfs(stoi(e[u].l),idx << 1);
if(e[u].r != "-") dfs(stoi(e[u].r),idx << 1 | 1);
}
int main()
{
cin >> n;
for(int i = 0; i < n; i ++)
{
string a,b;
cin >> a >> b;
if(a != "-") mp[stoi(a)] = 1;
if(b != "-") mp[stoi(b)] = 1;
e[i] = {a,b};
}
int u;
for(int i = 0; i < n; i ++) if(!mp[i]) u = i;// root
dfs(u,1);
if(last == n) cout << "YES" << ' ' << res << endl;
else cout << "NO" << ' ' << u << endl;
return 0;
}
边栏推荐
- Concurrent operation memory interaction
- [research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached
- 【工具跑SQL盲注】
- Flutter monitors volume to realize waveform visualization of audio
- [tools run SQL blind note]
- Compile and decompile GCC common instructions
- Three representations of signed numbers: original code, inverse code and complement code
- Number of uniform strings of leetcode simple problem
- Network security textual research recommendation
- Notes | numpy-07 Slice and index
猜你喜欢
Review the old and know the new: Notes on Data Science
Cross platform plug-in flutter for displaying local notifications_ local_ notifications
Leetcode simple question: check whether the string is an array prefix
JDBC database operation
Without 50W bride price, my girlfriend was forcibly dragged away. What should I do
[XSS bypass - protection strategy] understand the protection strategy and better bypass
Flutter monitors volume to realize waveform visualization of audio
I stepped on a foundation pit today
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Learning practice: comprehensive application of cycle and branch structure (I)
随机推荐
Market status and development prospect forecast of global button dropper industry in 2022
[luatos sensor] 1 light sensing bh1750
Coordinatorlayout appbarrayout recyclerview item exposure buried point misalignment analysis
UiPath实战(08) - 选取器(Selector)
Hire cashier (differential constraint)
Leetcode simple problem delete an element to strictly increment the array
[luatos sensor] 2 air pressure bmp180
Career planning of counter attacking College Students
Sdl2 + OpenGL glsl practice (Continued)
MySQL winter vacation self-study 2022 12 (3)
Market status and development prospect prediction of the global fire extinguisher industry in 2022
Wechat applet distance and map
@RequestMapping
Number of 1 in binary (simple difficulty)
"Niuke brush Verilog" part II Verilog advanced challenge
ZABBIX monitoring of lamp architecture (2): ZABBIX basic operation
Notes | numpy-09 Broadcast
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
[research materials] annual report of China's pension market in 2021 - Download attached
Summary of training competition (Lao Li's collection of questions)