#include <bits/stdc++.h>
using namespace std;
int n;
int hot[100005], du[100005];
int pre[100005];
int len[100005];
int t;
int p[100005];
void init() {
  for (int i = 0; i < 100005; i++) pre[i] = i;
  memset(hot, 0, sizeof(hot));
  memset(du, 0, sizeof(du));
  memset(len, 0, sizeof(len));
}
int c;
int find(int x, int s) {
  if (x == pre[x]) {
    if (du[x] == 1)
      return s + 1;
    else
      return s;
  } else {
    if (du[x] == 1)
      return find(pre[x], s + 1);
    else
      return s;
  }
}
void print(int x) {
  if (du[x] == 1) {
    p[t++] = x;
    if (x == pre[x]) return;
    print(pre[x]);
  }
}
void solve() {
  for (int i = 1; i <= n; i++) {
    if (hot[i]) {
      len[i] = find(pre[i], 1);
    }
  }
  int max = -1, k = 0;
  for (int i = 1; i <= n; i++) {
    if (len[i] > max) {
      max = len[i];
      k = i;
    }
  }
  cout << len[k] << endl;
  t = 0;
  p[t++] = k;
  print(pre[k]);
  for (int i = t - 1; i >= 0; i--) cout << p[i] << " ";
  cout << endl;
}
void input() {
  while (cin >> n) {
    init();
    for (int i = 1; i <= n; i++) {
      cin >> c;
      hot[i] = c;
    }
    for (int i = 1; i <= n; i++) {
      cin >> c;
      if (c == 0)
        ;
      else {
        du[c]++;
        pre[i] = c;
      }
    }
    solve();
  }
}
int main() {
  input();
  return 0;
}
