Problem:
Score : 2000 points

Problem Statement

You are given a rooted tree with N vertices.
The vertices are numbered 0, 1, ..., N-1.
The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i.

Initially, an integer a_i is written in Vertex i.
Here, (a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1).

You can execute the following operation at most 25 000 times. Do it so that the value written in Vertex i becomes i.

Choose a vertex and call it v. Consider the path connecting Vertex 0 and v.

Rotate the values written on the path. That is, For each edge (i, p_i) along the path, replace the value written in Vertex p_i with the value written in Vertex i (just before this operation), and replace the value of v with the value written in Vertex 0 (just before this operation).

You may choose Vertex 0, in which case the operation does nothing.

Constraints

2 \leq N \leq 2000

0 \leq p_i \leq i-1

(a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1).

Input

Input is given from Standard Input in the following format:

N
p_1 p_2 ... p_{N-1}
a_0 a_1 ... a_{N-1}

Output

In the first line, print the number of operations, Q.
In the second through (Q+1)-th lines, print the chosen vertices in order.

Sample Input 1

5
0 1 2 3
2 4 0 1 3

Sample Output 1

2
3
4

After the first operation, the values written in Vertex 0, 1, .., 4 are 4, 0, 1, 2, 3.

Sample Input 2

5
0 1 2 2
4 3 1 2 0

Sample Output 2

3
4
3
1

After the first operation, the values written in Vertex 0, 1, .., 4 are 3, 1, 0, 2, 4.

After the second operation, the values written in Vertex 0, 1, .., 4 are 1, 0, 2, 3, 4.

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int P[2020];
vector<int> E[2020];
int A[2020];
int D[2020];
vector<int> C,ret;
int RE[2020];
int L[2020],R[2020],eid;

void dfs(int cur,int d) {
	D[cur]=d;
	L[cur]=eid++;
	if(E[cur].size()==0) C.push_back(cur);
	FORR(e,E[cur]) dfs(e,d+1);
	R[cur]=eid;
}

int lca(int x,int y) {
	while(D[x]>D[y]) x=P[x];
	while(D[x]<D[y]) y=P[y];
	while(x!=y) {
		x=P[x];
		y=P[y];
	}
	return x;
}

int up(int x,int num) {
	while(num--) x=P[x];
	return x;
}

int rotate(int x) {
	static int count=24999;
	count--;
	assert(count>=0);
	//cout<<"rot "<<x<<endl;
	ret.push_back(x);
	vector<int> v;
	while(x) {
		v.push_back(x);
		x=P[x];
	}
	reverse(ALL(v));
	int i;
	FORR(x,v) {
		swap(A[x],A[P[x]]);
		RE[A[x]]=x;
		RE[A[P[x]]]=P[x];
	}
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>P[i+1];
		E[P[i+1]].push_back(i+1);
	}
	FOR(i,N) {
		cin>>A[i];
		RE[A[i]]=i;
	}
	dfs(0,1);
	while(1) {
		FOR(i,N) if(i!=A[i]) break;
		if(i==N) break;
		
		x=A[0];
		FOR(i,N) if(L[x]<=L[i]&&L[i]<R[x]&&!(L[x]<=L[A[i]]&&L[A[i]]<R[x])) {
			rotate(i);
			break;
		}
		
		//FOR(i,N) cout<<i<<":"<<A[i]<<"  ";
		//cout<<endl;
		
	}
	
	
	cout<<ret.size()<<endl;
	FORR(r,ret) cout<<r<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}