#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);
double EPS = 1e-7;
int INF = 1000000000;
int MOD = 1000000007;
int MAXINT = 2147483647;
long long INFLL = 1000000000000000000LL;
long long MAXLL = 9223372036854775807LL;
int ty[100005];
int pr[100005];
int sz[100005];
int vs[100005];
vector<int> lol;
int go(int k) {
  if (vs[k] != -1) return vs[k];
  if (sz[pr[k]] == 1 && pr[k]) {
    return vs[k] = 1 + go(pr[k]);
  } else
    return vs[k] = 0;
}
vector<int> ans;
void track(int k) {
  if (sz[pr[k]] == 1 && pr[k]) {
    track(pr[k]);
  }
  ans.push_back(k);
}
int main() {
  memset(vs, -1, sizeof(vs));
  int n;
  scanf("%d", &n);
  for (int(a) = (1); (a) <= (n); (a)++) {
    scanf("%d", &ty[a]);
  }
  for (int(a) = (1); (a) <= (n); (a)++) {
    scanf("%d", &pr[a]);
    sz[pr[a]]++;
  }
  pair<int, int> maks = make_pair(0, 0);
  for (int(a) = (1); (a) <= (n); (a)++) {
    if (ty[a]) (maks) = max((maks), (make_pair(1 + go(a), a)));
  }
  track(maks.second);
  printf("%d\n", (int)ans.size());
  for (int(a) = (0); (a) <= ((int)ans.size() - 1); (a)++) {
    printf("%d ", ans[a]);
  }
  puts("");
}
