#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:66777216")
int n;
int type[100000];
int degree[100000];
int nex[100000];
bool vis[100000];
vector<int> P;
int largest(int x, bool first, bool track = false) {
  if (vis[x]) return 0;
  vis[x] = true;
  int y = nex[x];
  if ((!first && type[x] == 1) || degree[y] >= 2 || y == -1) {
    if (track) P.push_back(x);
    return 1;
  } else {
    int ans = largest(y, false, track) + 1;
    if (track) P.push_back(x);
    return ans;
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> type[i];
  for (int i = 0; i < n; ++i) {
    cin >> nex[i];
    --nex[i];
    degree[nex[i]]++;
  }
  int ans = -1;
  int ansi;
  for (int i = 0; i < n; ++i) {
    if (type[i] == 1) {
      int t = largest(i, true);
      if (ans < t) {
        ans = t;
        ansi = i;
      }
    }
  }
  cout << ans << endl;
  memset(vis, 0, sizeof(vis));
  largest(ansi, true, true);
  for (int x : P) {
    cout << (x + 1) << ' ';
  }
  cout << endl;
  return 0;
}
