#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, k, n, a[111111], v[111111], tw[111111];
  scanf("%d", &n);
  for (int i = 1; i < n + 1; i++) tw[i] = 0;
  for (int i = 1; i < n + 1; i++) scanf("%d", &a[i]);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &v[i]);
    if (tw[v[i]])
      a[v[i]] = 2;
    else
      tw[v[i]] = 1;
  }
  int mx = -1, mx_i = -1;
  for (int i = 1; i < n + 1; i++) {
    if (a[i] == 1) {
      int j = v[i];
      int ans = 1;
      while (j && !a[j]) {
        j = v[j];
        ans++;
      }
      if (mx < ans) {
        mx = ans;
        mx_i = i;
      }
    }
  }
  cout << mx << endl;
  stack<int> val;
  val.push(mx_i);
  int j = v[mx_i];
  while (j && !a[j]) {
    val.push(j);
    j = v[j];
  }
  while (!val.empty()) {
    cout << val.top() << " ";
    val.pop();
  }
  cout << endl;
  return 0;
}
