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. vs2012+ winform+.net4.0发布如何在xp上运行

    今天在英文版vs2013打包发布4.0(非4.0 client)的winform时,遇到了在xp上无法运行的情况,.net framework 4.0在xp上已安装.在打包前,winform工程,即菜 ...

  2. vue-cli中src/main.js 的作用

    // The Vue build version to load with the `import` command // (runtime-only or standalone) has been ...

  3. Hashing - Hard Version

    Hashing - Hard Version Given a hash table of size N, we can define a hash function . Suppose that th ...

  4. [bzoj1867][Noi1999][钉子和小球] (动态规划)

    Description Input 第1行为整数n(2<=n<=50)和m(0<=m<=n).以下n行依次为木板上从上至下n行钉子的信息,每行中‘*’表示钉子还在,‘.’表示钉 ...

  5. hdu 5050 java程序求大数最大公约数

    import java.io.*; import java.math.*; import java.util.*; import java.text.*; public class Main { pu ...

  6. The Balance POJ 2142 扩展欧几里得

    Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of ...

  7. Srping Boot日志输出(转)

    说明:其实经过研究,在最新版本的Spring Boot中默认使用的是logback进行日志输出,其余的都没有引入.但是网上的教程说只要按照下面的文件列表引入对应的配置文件就会进行输出,这个没有实践过, ...

  8. 10、Java并发性和多线程-线程安全与不可变性

    以下内容转自http://ifeve.com/thread-safety-and-immutability/: 当多个线程同时访问同一个资源,并且其中的一个或者多个线程对这个资源进行了写操作,才会产生 ...

  9. PHP与WCF第一次亲密接触

    接触PHP第二天,要求PHP访问WCF服务 着实痛苦,无从下手啊. 在网上查了很多资料知道PHP访问WCF很方便 <?php $client = new SoapClient ( 'http:/ ...

  10. 微软消息队列MessageQueue(MQ)

    首先本地安装微软的消息队列服务器. 基础类: namespace Core.MessageQueueTest { public class TestQueue : IDisposable { prot ...