当前位置:网站首页>Symmetric binary tree [tree traversal]
Symmetric binary tree [tree traversal]
2022-07-07 06:18:00 【MC happy bitter Xiao afraid】
topic
Ideas :dfs Traverse n Nodes , Judge symmetry :
#include <bits/stdc++.h>
using namespace std ;
const int N = 10000010 ;
int l[N] , r[N] , a[N] ;
int m , ans = 1 ;
bool flag ;
inline int dfs (int x , int y , int s)
{
if (x == -1 && y == -1) return 0 ;
if (x == -1 || y == -1 && x != y)
{
flag = true ;
return 0 ;
}
if (a[x] != a[y])
{
flag = true ;
return 0 ;
}
return dfs (l[x] , r[y] , 2) + dfs (r[x] , l[y] , 2) + s ;
}
int main ()
{
scanf ("%d" , & m) ;
for (int i = 1; i <= m; i++) scanf ("%d" , & a[i]) ;
for (int i = 1; i <= m; i++) scanf ("%d%d" , & l[i] , & r[i]) ;
for (int i = 1; i <= m; i++)
{
int s = dfs (l[i] , r[i] , 3) ;
if (s > ans && flag == false) ans = s ;
flag = false ;
}
printf ("%d" , ans) ;
return 0 ;
}
边栏推荐
- Deep clustering: joint optimization of depth representation learning and clustering
- Ideas of high concurrency and high traffic seckill scheme
- On the discrimination of "fake death" state of STC single chip microcomputer
- 从“跑分神器”到数据平台,鲁大师开启演进之路
- 那些自损八百的甲方要求
- 关于STC单片机“假死”状态的判别
- JVM命令之 jstat:查看JVM统计信息
- Detailed explanation of platform device driver architecture in driver development
- PowerPivot - DAX (function)
- The boss always asks me about my progress. Don't you trust me? (what do you think)
猜你喜欢

LM小型可编程控制器软件(基于CoDeSys)笔记二十三:伺服电机运行(步进电机)相对坐标转换为绝对坐标

Apple CMS V10 template /mxone Pro adaptive film and television website template
![[FPGA] EEPROM based on I2C](/img/28/f4f2efda4b5feb973c9cf07d9d908f.jpg)
[FPGA] EEPROM based on I2C

Find duplicate email addresses

3428. Put apples

C note 13

693. Travel sequencing

rt-thread 中对 hardfault 的处理

laravel 使用腾讯云 COS5全教程

JVM命令之 jstack:打印JVM中线程快照
随机推荐
Storage of dental stem cells (to be continued)
cf:C. Column Swapping【排序 + 模拟】
Find duplicate email addresses
Value range of various datetimes in SQL Server 2008
ST表预处理时的数组证明
@Detailed differences between pathvariable and @requestparam
Rk3399 platform development series explanation (WiFi) 5.53, hostapd (WiFi AP mode) configuration file description
Rk3399 platform development series explanation (interruption) 13.10, workqueue work queue
K8s running Oracle
C. colonne Swapping [tri + Simulation]
JVM命令之- jmap:导出内存映像文件&内存使用情况
Experience of Niuke SQL
Jcmd of JVM command: multifunctional command line
安装mongodb数据库
c语言(结构体)定义一个User结构体,含以下字段:
Experience sharing of contribution of "management world"
VMware安装后打开就蓝屏
可极大提升编程思想与能力的书有哪些?
Qtthread, one of many methods of QT multithreading
Jstat of JVM command: View JVM statistics