#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long long mod7 = 1000000007;
const long long mod9 = 1000000009;
const int linf = 2000000000;
const long long llinf = 1000000000000000000ll;
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
pair<int, int> a[1000001];
vector<int> ans;
vector<int> gr[100001];
int p[100001];
int dep[100001];
bool used[100001];
int dfs(int v) {
  int cur = -linf;
  if (!used[v]) {
    used[v] = true;
    if (gr[v].size() <= 1)
      for (int i = 0; i < gr[v].size(); ++i) {
        int to = gr[v][i];
        if (a[to].first == 1) {
          cur = 1;
          p[v] = to;
        } else if (dep[to] >= 0) {
          if (dep[to] == linf) continue;
          cur = dep[to] + 1;
          p[v] = to;
        } else {
          dfs(to);
          if (dep[to] == linf) continue;
          cur = dep[to] + 1;
          p[v] = to;
        }
      }
  }
  if (cur == -linf)
    dep[v] = linf;
  else
    dep[v] = cur;
  used[v] = false;
  return cur;
}
int main() {
  int n, m, x;
  cin >> n;
  int best = 0;
  int d = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].first;
    if (!a[i].first)
      dep[i] = -linf;
    else
      best = i;
    p[i] = -1;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].second;
    if (a[i].second) {
      gr[a[i].second].push_back(i);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int k = dfs(i);
    if (k > d) {
      d = k;
      best = i;
    }
  }
  cout << d + 1 << endl;
  while (p[best] != -1) {
    cout << best << ' ';
    best = p[best];
  }
  cout << best;
  return 0;
}
