#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int maxn, maxid;
vector<int> nxt;
vector<int> op;
vector<int> cnt;
vector<int> ans;
int main() {
  scanf("%d", &n);
  op.assign(n + 1, 0);
  nxt.assign(n + 1, 0);
  cnt.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &op[i]);
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &nxt[i]);
    ++cnt[i];
    ++cnt[nxt[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (op[i]) {
      int sum = 1, j = i;
      while (nxt[j] && cnt[nxt[j]] <= 2) ++sum, j = nxt[j];
      if (sum > maxn) maxn = sum, maxid = i;
    }
  }
  int j = maxid;
  ans.push_back(j);
  while (nxt[j] && cnt[nxt[j]] <= 2) j = nxt[j], ans.push_back(j);
  printf("%d\n", maxn);
  for (int i = maxn - 1; i >= 0; --i) printf("%d ", ans[i]);
  puts("");
  return 0;
}
