当前位置:网站首页>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 ;
}
边栏推荐
- window下面如何安装swoole
- Array proof during st table preprocessing
- 骑士战胜魔王(背包&dp)
- [FPGA tutorial case 13] design and implementation of CIC filter based on vivado core
- JVM command - jmap: export memory image file & memory usage
- How to keep accounts of expenses in life
- JVM命令之 jstat:查看JVM统计信息
- 蚂蚁庄园安全头盔 7.8蚂蚁庄园答案
- Markdown 并排显示图片
- 当我们谈论不可变基础设施时,我们在谈论什么
猜你喜欢
软件测试的几个关键步骤,你需要知道
Go语学习笔记 - gorm使用 - 原生sql、命名参数、Rows、ToSQL | Web框架Gin(九)
10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
DC-7靶机
深度聚类:将深度表示学习和聚类联合优化
@pathvariable 和 @Requestparam的详细区别
绕过open_basedir
3531. 哈夫曼树
JVM命令之 jstack:打印JVM中线程快照
Check Point:企业部署零信任网络(ZTNA)的核心要素
随机推荐
JVM命令之 jstack:打印JVM中线程快照
[SQL practice] a SQL statistics of epidemic distribution across the country
How to keep accounts of expenses in life
693. Travel sequencing
Peripheral driver library development notes 43: GPIO simulation SPI driver
JVM monitoring and diagnostic tools - command line
雷特智能家居龙海祁:从专业调光到全宅智能,20年专注成就专业
开发者别错过!飞桨黑客马拉松第三期链桨赛道报名开启
谷歌 Chrome 浏览器发布 103.0.5060.114 补丁修复 0-day 漏洞
C面试24. (指针)定义一个含有20个元素的double型数组a
Chain storage of stack
Experience sharing of contribution of "management world"
Rk3399 platform development series explanation (WiFi) 5.53, hostapd (WiFi AP mode) configuration file description
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
Rk3399 platform development series explanation (WiFi) 5.52. Introduction to WiFi framework composition
Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)
苹果cms V10模板/MXone Pro自适应影视电影网站模板
安装VMmare时候提示hyper-v / device defender 侧通道安全性
K8s running Oracle
693. 行程排序