去你的萌新。。。
by wyhwyh @ 2019-02-14 14:04:11
@[wyhwyh](/space/show?uid=55032) 我连普及组都不能AK,为什么不是萌新
by YZhe @ 2019-02-14 14:05:54
@[Tryer](/space/show?uid=117655)
我是不会告诉你暴力可以过的
```cpp
#include <bits/stdc++.h>
#define rep(i,a,b) for(i=a;i<b;i++)
#define per(i,b,a) for(i=b;i>=a;i--)
#define For(i,a,b) for(i=a;i<=b;i++)
#define Forenska(it,c) for(register __typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
using namespace std;
int i,j;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
int x=0;
char ch=' ';
bool flag=false;
while(!isdigit(ch))
{
if(ch=='-')flag=true;
ch=getchar();
}
while(isdigit(ch))
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return flag?-x:x;
}
struct Node
{
Node *Lson;
Node *Rson;
int val;
int sons;
Node()
{
Lson=Rson=NULL;
}
};
int ans;
int cnt(Node* v)
{
if(v==NULL)return 0;
return v->sons=cnt(v->Lson)+cnt(v->Rson)+1;
}
bool check(Node* Left,Node* Right)
{
if(Left==NULL && Right==NULL)return true;
else if(Left==NULL || Right==NULL || Left->sons!=Right->sons || Left->val!=Right->val)return false;
else return check(Left->Lson,Right->Rson) && check(Left->Rson,Right->Lson);
}
void dfs(Node *v)
{
if(v==NULL)return;
if(check(v,v) && ans<v->sons)ans=v->sons;
dfs(v->Lson);
dfs(v->Rson);
}
int main()
{
vector <Node> tree;
int n=read();
tree.resize(n);
rep(i,0,n)tree[i].val=read();
rep(i,0,n)
{
int Ls=read(),Rs=read();
if(Ls!=-1)tree[i].Lson=&tree[Ls-1];
if(Rs!=-1)tree[i].Rson=&tree[Rs-1];
}
cnt(&tree[0]);
dfs(&tree[0]);
cout<<ans<<endl;
return 0;
}
```
by Smile_Cindy @ 2019-02-14 14:06:49
@[Tryer](/space/show?uid=117655)
https://www.luogu.org/blog/cqj/zui-hao-li-xie-di-fang-fa
by resftlmuttmotw @ 2019-02-14 14:08:29
@[Alpha](/space/show?uid=87058) 其实我的方法也比较暴力
by YZhe @ 2019-02-14 14:11:20
@[resftlmuttmotw](/space/show?uid=73992) 谢谢大佬,但我还是想把自己的方法先完善,再去参考别的思想
by YZhe @ 2019-02-14 14:13:00
确实是哈希冲突了,用了两个BASE就AC了
by YZhe @ 2019-02-14 15:13:41