bool cmp(int a,int b){return dfn[a]<dfn[b];}
#define pb push_back
vector<int>G[maxn];
int s[maxn],a[maxn],tp;
void push(int u)
{
if(u==1)return;
G[u].clear();
int lca=getlca(u,s[tp]);
if(lca==s[tp])return s[++tp]=u,void();
while(tp>1&&dep[lca]<dep[s[tp-1]])
G[s[tp-1]].pb(s[tp]),tp--;
if(s[tp-1]!=lca)G[lca].clear(),G[lca].pb(s[tp]),s[tp]=lca;
else G[lca].pb(s[tp--]);
s[++tp]=u;
}
inline void build(int n){
s[tp=1]=1,G[1].clear();
For(i,1,n)push(a[i]);
while(tp)G[s[tp-1]].push_back(s[tp]),tp--;
}