#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int sh[MAX], s[MAX], visit[MAX];
vector<int> v(MAX);
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &sh[i]);
  int c = -1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
    visit[s[i]]++;
    if (sh[i] == 1) {
      v[++c] = i;
    }
  }
  int index = 0, z = 0;
  for (int i = 0; i <= c; i++) {
    int j = s[v[i]];
    int x = 1;
    while (true) {
      if (visit[j] > 1 || (sh[j] == 1 && j != s[v[i]])) break;
      if (j == 0) {
        break;
      }
      x++;
      j = s[j];
    }
    if (x > z) {
      z = x;
      index = v[i];
    }
  }
  int i = 0;
  visit[0] = index;
  while (--z) {
    visit[++i] = s[index];
    index = s[index];
  }
  cout << i + 1 << endl;
  for (int j = i; j >= 0; j--) printf("%d ", visit[j]);
  return 0;
}
