此种方法会RE 6个点 但是当我数组改为son[maxn][2]时,可以AC
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
int fa[maxn],son[2][maxn];
void dfs_q(int now)
{
if(now==0)return ;
cout<<now<<" ";
dfs_q(son[1][now]);
dfs_q(son[2][now]);
}
void dfs_z(int now)
{
if(now==0)return ;
dfs_z(son[1][now]);
cout<<now<<" ";
dfs_z(son[2][now]);
// return ;
}
void dfs_h(int now)
{
if(now==0)return ;
dfs_h(son[1][now]);
dfs_h(son[2][now]);
cout<<now<<" ";
}
int main()
{
int n;
// std::ios::sync_with_stdio(false);
cin>>n;
for(int i=1;i<=n;i++)
{
int l,r;
cin>>l>>r;
fa[l]=i,fa[r]=i;
son[1][i]=l;
son[2][i]=r;
}
dfs_q(1);
cout<<endl;
dfs_z(1);
cout<<endl;
dfs_h(1);
return 0;
}