#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 9;
int t[MAXN], par[MAXN], in[MAXN];
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    --x;
    par[i] = x;
    in[x]++;
  }
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (t[i]) {
      int st = i;
      vector<int> tmp;
      while (par[st] != -1 && in[par[st]] <= 1) tmp.push_back(st), st = par[st];
      tmp.push_back(st);
      if (ans.size() < tmp.size()) ans = tmp;
    }
  }
  cout << ans.size() << endl;
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) cout << 1 + ans[i] << " ";
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
