#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    vector<int> A(n + 1), parent(n + 1), sum(n + 1);
    for (int i = 1; i <= n; i++) cin >> A[i];
    for (int i = 1; i <= n; i++) cin >> parent[i], sum[parent[i]]++;
    vector<int> tempAns, ans;
    for (int i = 1; i <= n; i++) {
      if (A[i]) {
        int k = i;
        tempAns.clear();
        tempAns.push_back(k);
        while (parent[k] && sum[parent[k]] == 1) {
          k = parent[k];
          tempAns.push_back(k);
        }
        if (tempAns.size() > ans.size()) ans = tempAns;
      }
    }
    cout << ans.size() << endl;
    for (int i = ans.size() - 1; i >= 0; i--) {
      if (i != (ans.size() - 1)) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
