#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int ans[MAXN], fg[MAXN], a[MAXN], vis[MAXN], tt[MAXN];
int n;
int dfs(int x) {
  if (x == 0) return 0;
  if (tt[x] > 1 || vis[x]) {
    vis[x] = 1;
    return 0;
  } else {
    return dfs(a[x]) + 1;
  }
}
void Print(int x) {
  if (x != 0 && tt[x] <= 1) {
    Print(a[x]);
    printf("%d ", x);
  } else
    ;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &fg[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(tt, 0, sizeof(tt));
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    tt[a[i]]++;
  }
  int Max = 0, m;
  for (int i = 1; i <= n; i++)
    if (fg[i]) {
      ans[i] = dfs(i);
      if (ans[i] > Max) {
        Max = ans[i];
        m = i;
      }
    }
  printf("%d\n", Max);
  Print(m);
  return 0;
}
