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. redis+php+mysql处理高并发实例

    一.实验环境ubuntu.php.apache或nginx.mysql二.利用Redis锁解决高并发问题,需求现在有一个接口可能会出现并发量比较大的情况,这个接口使用php写的,做的功能是接收 用户的 ...

  2. LA 3029 Subsequence

    LA 3029 A sequence of N positive integers (10 < N < 100 000), each of them less than or equal ...

  3. 《hello-world》第八次团队作业:Alpha冲刺

    项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...

  4. go 语言学习指南(一)

    参考资料: http://www.runoob.com/go/go-tutorial.html

  5. 【Codeforces 476C】Dreamoon and Sums

    [链接] 我是链接,点我呀:) [题意] 让你求出所有x的和 其中 (x div b)是(x mod b)的倍数 且x mod b不等于0 且(x div b)除(x mod b)的值(假设为k),k ...

  6. 20180725利用pmm监控管理mysql

    转自:https://www.percona.com/doc/percona-monitoring-and-management/architecture.html 报警机制https://www.p ...

  7. graylog 市场

    https://marketplace.graylog.org/addons/246dc332-7da7-4016-b2f9-b00f722a8e79

  8. VNC Viewer 设置屏幕分辨率-解决屏幕分辨率问题

    https://blog.csdn.net/runningtortoises/article/details/51425332

  9. codevs——1979 第K个数

    1979 第K个数  时间限制: 1 s  空间限制: 1000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给定一个长度为N(0<n<=10 ...

  10. Drools等规则引擎技术对比分析

    项目中需要设计开发一个规则引擎服务,于是调研了业界常用的规则引擎. 常见的规则引擎如下: Ilog JRules 是最有名的商用BRMS: Drools 是最活跃的开源规则引擎: Jess 是Clip ...