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)

	//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <bits/stdc++.h>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 2002;

int p[N], a[N], sz[N], h[N];
bool mark[N];
vector <int> g[N];

bool cmp(int a, int b) { return sz[a] > sz[b]; }

int calc(int v, int height = 0)
{
	h[v] = height;
	sz[v]++;
	for(int u : g[v])
		sz[v] += calc(u, height + 1);
	return sz[v];
}

int getLocation(int x)
{
	for(int u : g[x])
		if(!mark[u])
			return getLocation(u);
	return x;
}

int getLocationInMarks(int x, int v)
{
	int minChild = -1;
	for(int u : g[v])
		if(minChild == -1 || h[a[minChild]] > h[a[u]])
			minChild = u;
	if(minChild == -1 || h[a[minChild]] > h[x])
		return v;
	return getLocationInMarks(x, minChild);
}

void put(int x, int v)
{
	int lst = a[v];
	for(int u = p[v]; u != -1; u = p[u])
		swap(lst, a[u]);
	a[v] = x;
}

void fixMark(int v)
{
	for(; v != -1; v = p[v])
		for(int u : g[v])
			mark[v] &= mark[u];
}

int main()
{
	int n = in();
	p[0] = -1;
	for(int i = 1; i < n; i++)
		g[p[i] = in()].push_back(i);
	for(int i = 0; i < n; i++)
		a[i] = in();
	calc(0);
	for(int i = 0; i < n; i++)
		sort(g[i].begin(), g[i].end(), cmp);
	int cnt = 0;
	vector <int> moves;
	while(!mark[0])
	{
		cnt++;
		assert(cnt <= 25000);
		int pl = getLocation(a[0]);
		int p2 = pl;
		for(; mark[p2]; p2 = p[p2]);
		mark[p2] = true;
		
//		cerr << pl << " -> ";
		
		pl = getLocationInMarks(a[0], pl);
		moves.push_back(pl);

//		cerr << pl << endl;
		
		put(a[0], pl);
		fixMark(pl);

		/*
		for(int i = 0; i < n; i++)
			cerr << mark[i];
		cerr << endl;
		for(int i = 0; i < n; i++)
			cerr << a[i];
		cerr << endl;
		*/
	
	}
	for(int i = 0; i < n; i++)
		assert(a[i] == i);
	cout << moves.size() << endl;
	for(int x : moves)
		cout << x << endl;
}