#include <bits/stdc++.h>
using namespace std;
int t[100001], a[100001];
int main() {
  int n;
  scanf("%d", &n);
  std::vector<vector<int> > adj;
  vector<int> out(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
    vector<int> foo;
    adj.push_back(foo);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] > 0) out[a[i] - 1]++;
    adj[i].push_back(a[i] - 1);
  }
  int maxpath = 0, s = 0, u, path, beg;
  for (int i = 0; i < n; i++)
    if (t[i]) {
      beg = u = i, path = 0;
      while (u >= 0) {
        if (out[u] > 1) {
          if (maxpath < path) {
            maxpath = path;
            s = i;
          }
          path = 1;
          break;
        } else {
          u = adj[u][0];
          path++;
        }
      }
    }
  if (maxpath < path) {
    maxpath = path;
    s = beg;
  }
  printf("%d\n", maxpath);
  stack<int> p;
  while (out[s] <= 1) {
    p.push(s);
    s = adj[s][0];
  }
  while (!p.empty()) {
    printf("%d ", p.top() + 1);
    p.pop();
  }
  printf("\n");
  return 0;
}
