problem

一直忘记给这个题写题解了。

这题挺水的吧。

挺后悔当时没写出来。

#ifdef Dubug

#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
} int n ;
const int N = 1e6 + 5 ;
int a[N] ;
int Left[N] , Right[N] ;
int sum = 1 ; inline bool dfs(int x,int y) {//搜索能否有对称。
if(x == -1 and y == -1) return 1 ;
if(x == -1 or y == -1 or a[x] != a[y]) return 0 ;
sum += 2 ;
return (dfs(Left[x],Right[y]) and dfs(Left[y],Right[x])) ;
} signed main() {
n = In() ;
for(register int i=1;i<=n;i++) a[i] = In() ;
for(register int i=1;i<=n;i++) Left[i] = In() , Right[i] = In() ;
int ans = -0x7f ;
for(register int i=1;i<=n;i++) {//每个枚举一遍。n个节点。
sum = 1 ;//初始化
if(dfs(Left[i],Right[i])) ans = max(ans,sum) ;//如果有对称 那么更新ans
}
cout << ans << endl ;
return 0 ;
}

随机推荐

  1. Mysql Group by 分组取最小的实现方法

    表结构如下图:

  2. 数据库——mysql如何获取当前时间---https://www.cnblogs.com/Chenshuai7/p/5136469.html

    数据库——mysql如何获取当前时间 1.1 获得当前日期+时间(date + time)函数:now() -------https://www.cnblogs.com/Chenshuai7/p/51 ...

  3. java操作数据库的工具库(from韩顺平)

    需要引入jar包sqljdbc4.jar 其他关系型数据库只需要改动前面的连接过程,其他的一样 package com.cx.util; import java.io.FileInputStream; ...

  4. 0213微信ZABBIX报警

    简介 微信作为日常使用最频繁的工具,因此希望将微信接入zabbix报警. 微信企业号 1.申请微信企业号 申请后,请在“我的企业”页面下记录企业号的CorpID 2.添加通讯录 部门添加完成后,根据实 ...

  5. JRobin cpu 和 磁盘

    https://blog.csdn.net/li_zhongnan/article/details/3754053 https://blog.csdn.net/li_zhongnan/article/ ...

  6. HDU 1546 Idiomatic Phrases Game 求助!help!!!

    Idiomatic Phrases Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/O ...

  7. W3School Memcached教程(安装/基本操作/高级操作/命令)

    来自W3School的Memcached教程,基本上涵盖了从安装到状态监控的教程. 不过最全的应该是官方提供在GitHub上的Wiki教程,一切的标准都来自官方,参考:https://github.c ...

  8. js部分基础

    1.js的基本类型有哪些?引用类型有哪些?null和undefined的区别. 基础类型:number,null,regex,string,boolean 引用类型 : object,function ...

  9. laravel5.5更新到laravel5.7

    为什么要更新呢?因为项目用的第三方后台扩展包,有很些bug,不够完美.想要一个漂亮的后台,那个后台只支持5.7. 然后,我就开始更新框架了. 修改后:"php": "&g ...

  10. ssh2项目整合 struts2.1+hibernate3.3+spring3 基于hibernate注解和struts2注解

    项目文件夹结构例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveW9uZ3poaWFu/font/5a6L5L2T/fontsize/400/fi ...