当前位置:网站首页>对称的二叉树【树的遍历】
对称的二叉树【树的遍历】
2022-07-07 01:25:00 【MC快乐的苦Xiao怕】
题
思路:dfs遍历n个节点,判断是否对称:
#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 ;
}
边栏推荐
- Find duplicate email addresses
- Check Point:企业部署零信任网络(ZTNA)的核心要素
- 10W word segmentation searches per second, the product manager raised another demand!!! (Collection)
- 目标检测中的损失函数与正负样本分配:RetinaNet与Focal loss
- A very good JVM interview question article (74 questions and answers)
- 980. Different path III DFS
- Experience of Niuke SQL
- Jstack of JVM command: print thread snapshots in JVM
- STM32 key state machine 2 - state simplification and long press function addition
- Value range of various datetimes in SQL Server 2008
猜你喜欢

jvm命令之 jcmd:多功能命令行

window下面如何安装swoole

JVM monitoring and diagnostic tools - command line

Peripheral driver library development notes 43: GPIO simulation SPI driver

Go语学习笔记 - gorm使用 - gorm处理错误 | Web框架Gin(十)

JVM命令之- jmap:导出内存映像文件&内存使用情况
![[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core](/img/19/1a6d43c39f2cf810ba754ea9674426.png)
[FPGA tutorial case 13] design and implementation of CIC filter based on vivado core

Convert numbers to string strings (to_string()) convert strings to int sharp tools stoi();

Loss function and positive and negative sample allocation in target detection: retinanet and focal loss

If you don't know these four caching modes, dare you say you understand caching?
随机推荐
Reading notes of Clickhouse principle analysis and Application Practice (6)
go-microservice-simple(2) go-Probuffer
JVM监控及诊断工具-命令行篇
You don't know the complete collection of recruitment slang of Internet companies
3428. 放苹果
如果不知道这4种缓存模式,敢说懂缓存吗?
你不知道的互联网公司招聘黑话大全
Senior programmers must know and master. This article explains in detail the principle of MySQL master-slave synchronization, and recommends collecting
The solution of a simple algebraic problem
PTA ladder game exercise set l2-002 linked list de duplication
693. 行程排序
JVM command - jmap: export memory image file & memory usage
Flask1.1.4 Werkzeug1.0.1 源碼分析:啟動流程
SQL Server 2008 各种DateTime的取值范围
cf:C. Column Swapping【排序 + 模擬】
当我们谈论不可变基础设施时,我们在谈论什么
Cloud acceleration helps you effectively solve attack problems!
SAP Spartacus checkout 流程的扩展(extend)实现介绍
The boss always asks me about my progress. Don't you trust me? (what do you think)
Jstat of JVM command: View JVM statistics