#include <bits/stdc++.h>
const int maxn = 100001;
int t[maxn];
int a[maxn];
int b[maxn];
int res[maxn];
int n, ans;
int bf[maxn];
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &t[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (b[a[i]] == 0)
      b[a[i]] = i;
    else
      b[a[i]] = -1;
  }
}
void go(int u) {
  int l = 0;
  bf[l++] = u;
  res[u] = 1;
  while (true) {
    int v = bf[l - 1];
    if (a[v] == 0) break;
    if (t[a[v]]) break;
    if (b[a[v]] == -1) break;
    bf[l++] = a[v];
    res[u]++;
  }
}
void solve() {
  for (int i = 1; i <= n; i++) {
    if (t[i]) go(i);
    if (res[i] > res[ans]) ans = i;
  }
  int l = 0;
  bf[l++] = ans;
  while (true) {
    int v = bf[l - 1];
    if (a[v] == 0) break;
    if (t[a[v]]) break;
    if (b[a[v]] == -1) break;
    bf[l++] = a[v];
  }
  printf("%d\n", res[ans]);
  while (l--) printf("%d ", bf[l]);
}
int main() {
  read();
  solve();
}
