#include <bits/stdc++.h>
using namespace std;
int n, t[111111], was[111111], a[111111], ok, pos, used[111111];
vector<int> ans, vec;
void dfs(int v, int p) {
  used[v] = 1;
  vec.push_back(v);
  if (a[v] && was[a[v]] == 1) dfs(a[v], v);
  if (vec.size() > ans.size()) {
    ans.clear();
    ans = vec;
  }
  vec.clear();
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
    if (t[i]) pos = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i]) was[a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (t[i]) dfs(i, 0);
  printf("%d\n", ans.size());
  for (int i = ans.size() - 1; i >= 0; i--) printf("%d ", ans[i]);
}
