#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> v[N];
vector<int> w, q, g;
int p[N];
void recu(int x) {
  if (v[p[x]].size() != 1)
    return;
  else {
    g.push_back(p[x]);
    recu(p[x]);
  }
}
int main() {
  int n, m;
  int mx = -1;
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> m;
    if (m == 1) w.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> m;
    if (m > 0) {
      v[m].push_back(i);
      p[i] = m;
    }
  }
  for (int i = 0; i < w.size(); i++) {
    g.clear();
    g.push_back(w[i]);
    recu(w[i]);
    int p = g.size();
    if (p > mx) {
      mx = p;
      q.clear();
      for (int i = 0; i < g.size(); i++) q.push_back(g[i]);
    }
  }
  cout << mx << endl;
  for (int i = q.size() - 1; i >= 0; i--) cout << q[i] << " ";
  cout << endl;
}
