#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> Pre;
vector<int> Next;
vector<int> target;
vector<int> res;
void dfs(int v, vector<int> &tmp) {
  tmp.push_back(v);
  if (Pre[v].empty()) {
    if (tmp.size() > res.size()) res = tmp;
    tmp.pop_back();
    return;
  }
  for (auto u : Pre[v]) {
    if (Next[u] != 1) {
      if (tmp.size() > res.size()) res = vector<int>(tmp);
    } else {
      dfs(u, tmp);
    }
  }
  tmp.pop_back();
}
int main() {
  cin >> n;
  Pre = vector<vector<int>>(n + 1);
  Next = vector<int>(n + 1, 0);
  target = vector<int>(n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &target[i]);
  }
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d", &p);
    if (p != 0) {
      Next[p]++;
      Pre[i].push_back(p);
    }
  }
  vector<int> tmp;
  for (int i = 1; i <= n; i++) {
    if (target[i]) {
      dfs(i, tmp);
    }
  }
  printf("%d\n", res.size());
  for (int i = res.size() - 1; i >= 0; i--) {
    printf("%d", res[i]);
    if (i != 0) printf(" ");
  }
  return 0;
}
