边界少考虑了一个。
by vibrant72 @ 2018-11-20 21:26:16
@[wangshengjun33](/space/show?uid=53308) 边界少了哪个?
望大佬说明
by 任弈凡 @ 2018-11-22 12:36:13
```
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
struct twree{
ll left,right,num;
};
twree a[2300003];
ll n;
ll ans;
ll sum=1;
ll read() {
ll x=0,f=1;
char ch=getchar() ;
while(ch<'0'||ch>'9') {
if(ch=='-') f=-f;
ch=getchar();
}
while(ch>='0'&&ch<='9') {
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
void dfs(ll x,ll y) {
if(a[x].num==a[y].num) {
sum+=2;
}
else if(a[x].num!=-1||a[y].num!=-1) {
sum=1;
return ;
}
else if(a[x].right!=-1||a[y].left!=-1||a[y].right!=-1||a[x].left!=-1) {
//cout<<sum<<endl;
sum=1;
return ;
}
//cout<<a[x].left<<" "<<a[y].right<<" "<<sum<<endl;
if(a[x].right==-1&&a[y].left!=-1) {
sum=1;
return ;
}
if(a[x].left==-1&&a[y].right!=-1) {
sum=1;
return ;
}
if(a[y].left==-1&&a[x].right!=-1) {
//cout<<a[x].left<<" "<<a[y].right<<" "<<sum<<endl;
sum=1;
return ;
}
if(a[y].right==-1&&a[x].left!=-1) {
sum=1;
return ;
}
if(a[x].right!=-1&&a[y].left!=-1) {
//cout<<x<<" "<<y<<" "<<a[x].right<<" "<<a[y].left<<endl;
dfs(a[x].right,a[y].left);
}
if(a[y].right!=-1&&a[x].left!=-1) {
//cout<<x<<" "<<y<<" "<<a[x].left<<" "<<a[y].right<<endl;
dfs(a[x].left,a[y].right);
}
if(a[x].left==-1&&a[x].right==-1) return ;
if(a[y].left==-1&&a[y].right==-1) return ;
}
int main() {
n=read();
/*if(n==1) {
cout<<n;
return 0;
}*/
for(ll i=1;i<=n;i++) {
a[i].num=read();
}
for(ll i=1;i<=n;i++) {
a[i].left=read();
a[i].right=read();
}
for(ll i=1;i<=n;i++) {
if(a[i].left==-1||a[i].right==-1) continue;
dfs(a[i].left,a[i].right);
ans=max(ans,sum);
sum=1;
}
cout<<ans<<endl;
return 0;
}
```
程序(92)
by 任弈凡 @ 2018-11-22 13:09:45
等于0的时候没考虑
by vibrant72 @ 2018-11-22 19:26:38
@[wangshengjun33](/space/show?uid=53308) 恕我愚笨,没听懂您在讲什么
by 任弈凡 @ 2018-11-25 00:04:30
@[wangshengjun33](/space/show?uid=53308) 请问那个边界是$0?$
by 任弈凡 @ 2018-11-25 14:39:03