当前位置:网站首页>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;
}边栏推荐
- Triangular rasterization
- The 19th Zhejiang I. barbecue
- Notes | numpy-10 Iterative array
- 2022-02-11 daily clock in: problem fine brush
- [SQL injection point] location and judgment of the injection point
- Wechat applet waterfall flow and pull up to the bottom
- Notes | numpy-07 Slice and index
- I stepped on a foundation pit today
- Esp32-c3 learning and testing WiFi (II. Wi Fi distribution - smart_config mode and BlueIf mode)
- 雇佣收银员(差分约束)
猜你喜欢
![[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree](/img/0f/bc8c44aee7a2c9dccac050b1060017.jpg)
[clock 223] [binary tree] [leetcode high frequency]: 102 Sequence traversal of binary tree

Leetcode simple question: check whether the array is sorted and rotated

Actual combat 8051 drives 8-bit nixie tube

关于开学的准备与专业认知

Sdl2 + OpenGL glsl practice (Continued)

Automatic voltage rise and fall 5-40v multi string super capacitor charging chip and solution

Analysis of proxy usage of ES6 new feature

Leetcode simple question: the key with the longest key duration

Basic use of Metasploit penetration testing framework

Keepalived热备与HAProxy
随机推荐
Introduction to message queuing (MQ)
Thesis reading_ Chinese medical model_ eHealth
The usage of micro service project swagger aggregation document shows all micro service addresses in the form of swagger grouping
Preparation for school and professional cognition
Online VR model display - 3D visual display solution
[luatos sensor] 2 air pressure bmp180
[SQL injection] joint query (the simplest injection method)
Day 51 - tree problem
Thesis reading_ Tsinghua Ernie
[USACO 2009 Dec S]Music Notes
[develop wechat applet local storage with uni app]
5-36v input automatic voltage rise and fall PD fast charging scheme drawing 30W low-cost chip
Shell script Basics - basic grammar knowledge
Uipath practice (08) - selector
Market status and development prospect prediction of global colorimetric cup cover industry in 2022
String matching: find a substring in a string
I've seen a piece of code in the past. I don't know what I'm doing. I can review it when I have time
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)
Why does I start with =1? How does this code work?
带有注意力RPN和多关系检测器的小样本目标检测网络(提供源码和数据及下载)...