#include <bits/stdc++.h>
const int maxn = 100000 + 5;
struct PP {
  int to, next;
} edge[maxn * 5];
int head[maxn], vis[maxn], ru[maxn], pa[maxn], path[maxn], is[maxn], a[maxn],
    cnt[maxn];
int E, dep[maxn];
void init() {
  memset(head, -1, sizeof(head));
  E = 0;
}
void newedge(int u, int to) {
  edge[E].to = to;
  edge[E].next = head[u];
  head[u] = E++;
}
int max(int a, int b) { return a > b ? a : b; }
int mx, ans, flag;
void dfs(int u) {
  mx = max(mx, dep[u]);
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    dep[to] = dep[u] + 1;
    dfs(to);
  }
}
void DFS(int u, int d) {
  if (flag) return;
  if (d == ans + 1) {
    for (int i = ans; i >= 1; i--) printf("%d ", path[i]);
    puts("");
    flag = 1;
    return;
  }
  for (int i = head[u]; i != -1; i = edge[i].next) {
    int to = edge[i].to;
    path[d] = to;
    DFS(to, d + 1);
    if (flag) return;
  }
}
int main() {
  init();
  int n, u;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &is[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    cnt[a[i]]++;
  }
  for (int i = 1; i <= n; i++)
    if (!is[i] && a[i]) {
      if (cnt[i] == 1 && cnt[a[i]] == 1 && !is[a[i]]) newedge(i, a[i]);
    } else if (a[i] && cnt[a[i]] == 1)
      newedge(i, a[i]);
  for (int i = 1; i <= n; i++) cnt[i] = 0;
  ans = 0;
  int id;
  for (int i = 1; i <= n; i++)
    if (is[i]) {
      mx = 0;
      dep[i] = 1;
      dfs(i);
      if (mx > ans) id = i, ans = mx;
    }
  printf("%d\n", ans);
  path[1] = id;
  flag = 0;
  DFS(id, 2);
}
