#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  bool ishotel[n + 1];
  int one[n + 1];
  bool forbidden[n + 1];
  memset(one, 0, sizeof(one));
  memset(forbidden, 0, sizeof(forbidden));
  vector<int> hotels;
  int inedge[n];
  for (int i = 1; i <= n; i++) {
    cin >> ishotel[i];
    if (ishotel[i]) hotels.push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    cin >> inedge[i];
    one[inedge[i]]++;
    if (inedge[i] && one[inedge[i]] > 1) {
      forbidden[inedge[i]] = true;
    }
  }
  int ret = -1;
  vector<int> path;
  for (int i = 0; i < hotels.size(); i++) {
    int u = hotels[i], cnt = 1;
    vector<int> cpath;
    cpath.push_back(u);
    while (1) {
      if (!forbidden[inedge[u]] && inedge[u] != 0) {
        cnt++;
        cpath.push_back(inedge[u]);
        u = inedge[u];
      } else
        break;
    }
    if (cnt > ret) {
      ret = cpath.size();
      if (path.size() != 0) path.clear();
      for (int i = 0; i < cpath.size(); i++) path.push_back(cpath[i]);
    }
  }
  cout << ret << endl;
  reverse(path.begin(), path.end());
  for (int i = 0; i < path.size(); i++) {
    if (i != 0) cout << " ";
    cout << path[i];
  }
  cout << endl;
  return 0;
}
