当前位置:网站首页>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;
}边栏推荐
- JDBC database operation
- Wechat applet waterfall flow and pull up to the bottom
- Symbol of array element product of leetcode simple problem
- Flutter monitors volume to realize waveform visualization of audio
- Market status and development prospect prediction of the global forward fluorescent microscope industry in 2022
- Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
- 【XSS绕过-防护策略】理解防护策略,更好的绕过
- 50 practical applications of R language (36) - data visualization from basic to advanced
- 【PHP漏洞-弱类型】基础知识、php弱相等、报错绕过
- Introduction to JVM principle
猜你喜欢

Review the old and know the new: Notes on Data Science

Uipath practice (08) - selector
![[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)](/img/2a/362f3b0491f721d89336d4f468c9dd.jpg)
[set theory] relation properties (reflexivity | reflexivity theorem | reflexivity | reflexivity theorem | example)

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

逆袭大学生的职业规划
![[research materials] annual report of China's pension market in 2021 - Download attached](/img/24/622aeeb38de16ac84128b362ceeddb.jpg)
[research materials] annual report of China's pension market in 2021 - Download attached

论文阅读_ICD编码_MSMN

Do you know UVs in modeling?

Truncated sentences of leetcode simple questions

Three representations of signed numbers: original code, inverse code and complement code
随机推荐
Do you know UVs in modeling?
LVS load balancing cluster of efficient multi-purpose cluster (NAT mode)
Shuttle + Alluxio 加速内存Shuffle起飞
Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
Introduction to message queuing (MQ)
Market status and development prospect prediction of global neutral silicone sealant industry in 2022
Learn to use the idea breakpoint debugging tool
The programmer resigned and was sentenced to 10 months for deleting the code. JD came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
Sdl2 + OpenGL glsl practice (Continued)
The principle is simple, but I don't know how to use it? Understand "contemporaneous group model" in one article
Leetcode simple problem delete an element to strictly increment the array
ZABBIX monitoring of lamp architecture (3): zabbix+mysql (to be continued)
Leetcode simple question: check whether the string is an array prefix
Pyqt control part (II)
Shell script -- condition judgment
Kept hot standby and haproxy
Market status and development prospect prediction of the global fire extinguisher industry in 2022
[luatos sensor] 2 air pressure bmp180
[set theory] relational representation (relational matrix | examples of relational matrix | properties of relational matrix | operations of relational matrix | relational graph | examples of relationa
[PHP vulnerability weak type] basic knowledge, PHP weak equality, error reporting and bypassing