#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
int n, m;
int a[100005], b[100005], f[100005], pr[100005];
vector<int> ans, t;
void Load() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
}
void Solve() {
  int k, j, kmax = 0;
  for (int i = 1; i <= n; i++)
    if (f[b[i]] == 0)
      f[b[i]] = 1;
    else
      f[b[i]] = -1;
  for (int i = 1; i <= n; i++)
    if (f[b[i]] == 1) pr[i] = b[i];
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      t.erase(t.begin(), t.end());
      t.push_back(i);
      k = 1;
      j = i;
      while (pr[j] != 0) {
        k++;
        j = pr[j];
        t.push_back(j);
      }
      if (kmax < k) {
        kmax = k;
        ans = t;
      }
    }
  cout << kmax << endl;
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << " ";
}
int main() {
  Load();
  Solve();
  return 0;
}
