#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100100;
int tp[maxn], deg[maxn], path[maxn], cnt, ptr;
struct node {
  int v;
  node *next;
} edge[maxn], *head[maxn];
void adde(int u, int v) {
  edge[cnt].v = v;
  edge[cnt].next = head[u];
  head[u] = &edge[cnt++];
}
int main() {
  int n, a, i, ans, len, alen;
  node *p;
  while (~scanf("%d", &n)) {
    cnt = alen = 0;
    ans = -1;
    memset(head, 0, sizeof head);
    memset(deg, 0, sizeof deg);
    for (i = 1; i <= n; i++) scanf("%d", tp + i);
    for (i = 1; i <= n; i++) {
      scanf("%d", &a);
      if (a) {
        adde(i, a);
        deg[a]++;
      }
    }
    for (i = 1; i <= n; i++) {
      if (tp[i]) {
        len = 1;
        p = head[i];
        while (p != NULL && deg[p->v] <= 1) {
          len++;
          p = head[p->v];
        }
        if (len > alen) {
          alen = len;
          ans = i;
        }
      }
    }
    path[0] = ans;
    for (p = head[ans], ptr = i = 1; i < alen; i++) {
      path[ptr++] = p->v;
      p = head[p->v];
    }
    printf("%d\n", alen);
    for (i = ptr - 1; i > 0; i--) printf("%d ", path[i]);
    printf("%d\n", path[0]);
  }
  return 0;
}
