#include <bits/stdc++.h>
using namespace std;
int pel(string s) {
  string t;
  t = s;
  reverse(t.begin(), t.end());
  if (s == t) return 1;
  return 0;
}
string toString(int n) {
  ostringstream ost;
  ost << n;
  ost.flush();
  return ost.str();
}
int toInt(string s) {
  int r = 0;
  istringstream sin(s);
  sin >> r;
  return r;
}
bool isprime(int m) {
  if (m < 2) return 0;
  for (int i = 2; i * i <= m; i++)
    if (m % i == 0) return 0;
  return 1;
  return 0;
}
struct data {
  long long value;
  long long index;
};
int A[100005];
int B[100005];
int du[100005];
int ans[100005];
int result;
bool vis[100005];
int DFS(int x, int dep) {
  if (A[B[x]] || B[x] == 0 || du[B[x]] > 1) {
    if (dep > result) {
      result = dep;
      ans[dep] = x;
      return 1;
    }
    return 0;
  }
  if (DFS(B[x], dep + 1)) {
    ans[dep] = x;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  int i;
  while (cin >> n) {
    memset(du, 0, sizeof(du));
    memset(vis, 0, sizeof(vis));
    for (i = 1; i < n + 1; i++) cin >> A[i];
    for (i = 1; i < n + 1; i++) {
      cin >> B[i];
      ++du[B[i]];
    }
    result = 0;
    for (i = 1; i < n + 1; i++) {
      if (A[i]) DFS(i, 1);
    }
    cout << result << "\n";
    for (int i = result; i >= 1; i--) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
}
