#include <bits/stdc++.h>
using namespace std;
int arr1[100001];
int arr2[100001];
int main() {
  int n;
  cin >> n;
  vector<int> h;
  int a;
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if (a == 1) h.push_back(i);
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a;
    if (a == 0) continue;
    if (arr2[a] != 0) {
      arr1[arr2[a]] = 0;
      continue;
    }
    arr1[i] = a;
    arr2[a] = i;
  }
  int ans = 0, ansh = h[0];
  for (int i = 0; i < h.size(); ++i) {
    int a = h[i], tmp = 0;
    do {
      a = arr1[a];
      ++tmp;
    } while (a != 0);
    if (tmp > ans) {
      ans = tmp;
      ansh = h[i];
    }
  }
  cout << ans << endl;
  vector<int> v(ans);
  a = ansh;
  do {
    --ans;
    v[ans] = a;
    a = arr1[a];
  } while (a != 0);
  for (int i = 0; i < v.size(); ++i) cout << v[i] << " ";
  return 0;
}
