#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g;
vector<int> type;
vector<int> outDeg;
vector<bool> vis;
int maxStart;
int maxEnd;
int maxLen;
void findMax(int v, int start, int len) {
  vis[v] = true;
  len++;
  if (start == -1) {
    start = v;
  }
  if (len > maxLen) {
    maxLen = len;
    maxStart = start;
    maxEnd = v;
  }
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (type[u] == 0 && outDeg[u] == 1) {
      findMax(u, start, len);
    }
  }
}
stack<int> path;
void GetRoute(int v, int end) {
  path.push(v);
  if (v == end) {
    return;
  }
  GetRoute(g[v][0], end);
}
void PrintRoute(int v, int end) {
  GetRoute(v, end);
  while (path.size()) {
    cout << path.top() + 1 << " ";
    path.pop();
  }
}
int main() {
  int n;
  cin >> n;
  type.resize(n);
  g.resize(n);
  vector<bool> isRoot(n, true);
  for (int i = 0; i < n; i++) {
    cin >> type[i];
  }
  outDeg = vector<int>(n, 0);
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    if (l != 0) {
      --l;
      g[i].push_back(l);
      outDeg[l]++;
    }
  }
  maxLen = -1;
  for (int i = 0; i < n; i++) {
    if (type[i] == 1) {
      vis = vector<bool>(n, false);
      findMax(i, -1, 0);
    }
  }
  cout << maxLen << endl;
  PrintRoute(maxStart, maxEnd);
  cout << endl;
  return 0;
}
