#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9;
int n;
vector<int> adj[N];
int dp[N], parent[N];
;
int solve(int v, int par = -1) {
  if (dp[v] != -1) return dp[v];
  dp[v] = -inf;
  int deg = adj[v].size() - (par != -1);
  if (deg != 1) return dp[v];
  for (auto u : adj[v]) {
    int x = solve(u) + 1;
    if (x > dp[v]) parent[v] = u, dp[v] = x;
  }
  return dp[v];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  memset(dp, -1, sizeof dp);
  memset(parent, -1, sizeof parent);
  for (int i = 0; i < n; i++) {
    int type;
    cin >> type;
    if (type == 1) dp[i] = 1;
  }
  for (int i = 0; i < n; i++) {
    int par;
    cin >> par;
    par--;
    if (par >= 0) adj[par].push_back(i);
  }
  int ans = 0, st = -1;
  for (int i = 0; i < n; i++) {
    if (ans < solve(i)) {
      st = i;
      ans = solve(i);
    }
  }
  cout << ans << "\n";
  while (st != -1) {
    cout << st + 1 << " ";
    st = parent[st];
  }
  cout << "\n";
}
