#include <bits/stdc++.h>
int t[100010], a[100010];
int dig[100010];
int step[100010], vis[100010];
int n;
void dfs(int x) {
  vis[x] = 1;
  if (a[x] == 0 || t[a[x]] == 1 || dig[a[x]] != 1 || vis[a[x]] == 1) {
    step[x] = 1;
    return;
  }
  if (vis[a[x]] == 0) dfs(a[x]);
  step[x] = step[a[x]] + 1;
}
void output(int x) {
  int pre = a[x];
  vis[x] = 1;
  if (pre == 0 || t[pre] == 1 || dig[pre] != 1 || vis[pre] == 1)
    ;
  else
    output(pre);
  printf("%d ", x);
}
int main() {
  int i, ans;
  while (~scanf("%d", &n)) {
    memset(dig, 0, sizeof(dig));
    for (i = 1; i <= n; i++) scanf("%d", &t[i]);
    for (i = 1; i <= n; i++) scanf("%d", &a[i]), dig[a[i]]++;
    ans = -1;
    memset(vis, 0, sizeof(vis));
    for (i = 1; i <= n; i++)
      if (t[i]) {
        dfs(i);
        if (ans == -1 || step[ans] < step[i]) ans = i;
      }
    printf("%d\n", step[ans]);
    memset(vis, 0, sizeof(vis));
    output(ans);
    printf("\n");
  }
  return 0;
}
