#include <bits/stdc++.h>
using namespace std;
long long vis[100500];
long long t[100500];
long long a[100500];
long long par[100500];
long long val[100500];
vector<long long> to[100500];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  fill(par, par + 100500, -1);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    if (!a[i]) continue;
    a[i]--;
    par[i] = a[i];
    to[a[i]].push_back(i);
  }
  for (long long i = 0; i < n; i++) {
    if (to[i].size() > 1) {
      for (auto u : to[i]) {
        par[u] = -1;
      }
    }
  }
  queue<long long> q;
  for (long long i = 0; i < n; i++) {
    if (par[i] == -1) {
      q.push(i);
      val[i] = 1;
      continue;
    }
  }
  long long ans = -1, res;
  while (!q.empty()) {
    long long tmp = q.front();
    vis[tmp] = 1;
    q.pop();
    if (to[tmp].size() > 1) {
      for (auto u : to[tmp]) {
        if (vis[u]) continue;
        val[u] = 1;
        q.push(u);
        par[u] = -1;
        vis[u] = 1;
      }
    } else if (to[tmp].size() == 1) {
      if (vis[to[tmp][0]]) continue;
      val[to[tmp][0]] = val[tmp] + 1;
      q.push(to[tmp][0]);
    } else {
      if (t[tmp] == 1) {
        if (val[tmp] > ans) {
          ans = val[tmp];
          res = tmp;
        }
      }
    }
  }
  assert(ans != -1);
  vector<long long> v;
  while (res != -1) {
    v.push_back(res + 1);
    res = par[res];
  }
  reverse(v.begin(), v.end());
  cout << v.size() << '\n';
  for (auto now : v) {
    cout << now << ' ';
  }
  return 0;
}
