#include <bits/stdc++.h>
using namespace std;
int ok[200005];
int hotels[200005];
int vis[200005];
int cnt[200005];
int parent[200005];
int num;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> hotels[i];
  for (int i = 1; i <= n; i++) {
    cin >> parent[i];
    cnt[parent[i]]++;
  }
  vector<long long int> ans, v;
  for (int i = n; i >= 1; i--) {
    if (hotels[i] && vis[i] == 0) {
      v.clear();
      long long int curr = i;
      while (1) {
        v.push_back(curr);
        vis[curr] = 1;
        if (parent[curr] == 0 || cnt[parent[curr]] > 1) break;
        curr = parent[curr];
      }
      if (ans.size() < v.size()) ans = v;
    }
  }
  cout << ans.size() << endl;
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
  return 0;
}
