@[Curtain](/space/show?uid=32309) 一定要注意判断要加的节点和当前点是否相等,相等直接跳过。我也是因为这个提交了好几天
by AC_Evil @ 2017-09-04 23:08:40
改过了,还是不行
```cpp
//P2171 Hz吐泡泡
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,cnt,k,l,r,x,p;
const int maxn=300005;
int left_son[maxn],right_son[maxn],v[maxn];
inline int read() {
int x = 0,tmp = 1;char ch = getchar();
while( ch < '0' || ch > '9' ) { if( ch == '-' ) tmp = -1; ch = getchar(); }
while( ch >= '0' && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); }
return x * tmp;
}
void endorder(int i)
{
if(i==0)return;
endorder(left_son[i]);
endorder(right_son[i]);
cout<<v[i]<<endl;
}
void make_searchtree(int i,int x) //把x加到以i为根结点的子树中
{
if(x!=v[i])
{
if(x<v[i]){
if(left_son[i]==0){
cnt++;v[cnt]=x;left_son[i]=cnt;
}
else make_searchtree(left_son[i],x);
}
else{
if(right_son[i]==0){
cnt++;v[cnt]=x;right_son[i]=cnt;
}
else make_searchtree(right_son[i],x);
}
}
}
int h(int i){ //计算树的高度
if(i==0) return 0;
return max(h(left_son[i]),h(right_son[i]))+1;
}
int main(){
scanf("%d",&n);
scanf("%d",&x);
cnt=1; v[1]=x; //以第一个元素为根
for(int i=2;i<=n;i++){
x=read();
make_searchtree(1,x);
}
cout<<"deep="<<h(1)<<endl;
endorder(1);
return 0;
}
```
by Curtain @ 2017-09-06 22:30:40