#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> h(n + 5);
  vector<long long> deg(n + 5, 0), a(n + 5, 0);
  for (long long i = 1; i <= n; i++) cin >> h[i];
  for (long long i = 1; i <= n; i++) cin >> a[i], deg[a[i]]++;
  long long c = -1;
  long long maxi = 0;
  for (long long i = 1; i <= n; i++) {
    if (h[i] == 1) {
      long long x = a[i];
      long long cnt = 1;
      while (x > 0 && deg[x] == 1) cnt++, x = a[x];
      if (cnt > maxi) {
        maxi = cnt;
        c = i;
      }
    }
  }
  vector<long long> temp;
  temp.push_back(c);
  c = a[c];
  while (c > 0 && deg[c] == 1) temp.push_back(c), c = a[c];
  long long l = (long long)temp.size();
  cout << l << "\n";
  for (long long i = l - 1; i >= 0; i--) cout << temp[i] << " ";
}
