#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int INFINITE = 0x3f3f3f3f;
template <class T>
inline void checkmin(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline T lowbit(T n) {
  return (n ^ (n - 1)) & n;
}
template <class T>
inline int countbit(T n) {
  return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<string> VS;
const int MAXN = 100001;
int father[MAXN], deg[MAXN], type[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = (int)(0); i < (int)(n); i++) cin >> type[i];
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> father[i];
    --father[i];
  }
  for (int i = (int)(0); i < (int)(n); i++)
    if (father[i] != -1) {
      deg[father[i]]++;
    }
  VI res;
  res.clear();
  for (int i = (int)(0); i < (int)(n); i++)
    if (type[i]) {
      int cur = i;
      VI temp;
      temp.clear();
      do {
        temp.push_back(cur + 1);
        cur = father[cur];
      } while (cur != -1 && deg[cur] == 1);
      if (temp.size() > res.size()) res = temp;
    }
  reverse((res).begin(), (res).end());
  cout << res.size() << endl;
  for (int i = (int)(0); i < (int)(res.size()); i++)
    cout << res[i] << (i == res.size() - 1 ? "\n" : " ");
  return 0;
}
