#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const long long INFL = 3e18 + 1;
const double pi = acos(-1.0);
int n, is[N], p[N];
vector<int> comp, ans;
int mx;
int cnt[N];
void dfs(int v) {
  comp.push_back(v);
  if (cnt[p[v]] == 1 && !is[p[v]]) dfs(p[v]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> is[i];
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    if (p[i] != 0)
      cnt[p[i]]++;
    else
      cnt[p[i]] = INF;
  }
  for (int i = 1; i <= n; i++) {
    if (is[i] == 1) {
      comp.clear();
      dfs(i);
      if (comp.size() > mx) {
        mx = comp.size();
        ans = comp;
      }
    }
  }
  cout << ans.size() << endl;
  reverse(ans.begin(), ans.end());
  for (auto i : ans) cout << i << ' ';
  return 0;
}
