#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i <= n; ++i) cin >> a[i];
  int b[n + 1];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  int dp[n + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; ++i) dp[b[i]]++;
  vector<int> first;
  for (int i = 1; i <= n; ++i) {
    if (a[i] == 1) {
      vector<int> an;
      an.clear();
      an.push_back(i);
      int j = b[i];
      int tmp = i;
      while (tmp > 0) {
        j = b[tmp];
        if (j <= 0) break;
        if (dp[j] > 1) break;
        an.push_back(j);
        tmp = j;
      }
      if (an.size() > first.size()) {
        first = an;
      }
    }
  }
  cout << first.size() << endl;
  reverse(first.begin(), first.end());
  for (int i = 0; i < first.size(); ++i) cout << first[i] << " ";
  cout << endl;
  return 0;
}
