#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;
void stndrtn() {}
const bool flag = 0;
const int N = 1e5 + 10;
int p[N], cnt[N];
void ma1n() {
  int n;
  cin >> n;
  vector<int> t(n);
  for (int& first : t) {
    cin >> first;
  }
  for (int i = 0, first; i < n; ++i) {
    cin >> first, first--;
    p[i] = first, cnt[first]++;
  }
  int ans = 0, v = -1;
  for (int i = 0; i < n; ++i) {
    if (t[i] == 1) {
      int first = p[i], len = 1;
      while (~first && cnt[first] == 1) {
        first = p[first], len++;
      }
      if (len > ans) {
        ans = len, v = i;
      }
    }
  }
  vector<int> path = {v};
  v = p[v];
  while (~v && cnt[v] == 1) {
    path.push_back(v);
    v = p[v];
  }
  reverse(path.begin(), path.end());
  cout << ans << "\n";
  for (int first : path) {
    cout << first + 1 << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr), stndrtn();
  int ts = 1;
  if (flag) {
    cin >> ts;
  }
  while (ts--) {
    ma1n();
  }
  return 0;
}
