#include <bits/stdc++.h>
using namespace std;
int flag[100005];
int dp[100005];
bool vis[100005];
vector<int> e[100005];
void dfs(int s) {
  if (dp[s] != -2) return;
  if (flag[s]) {
    dp[s] = 1;
    vis[s] = true;
    return;
  }
  if ((e[s].size() >= 2) || (e[s].size() == 0)) {
    dp[s] = -1;
    vis[s] = true;
    return;
  }
  int to = e[s][0];
  if (dp[to] == -2 && !vis[to]) {
    vis[to] = true;
    dfs(to);
  } else if (dp[to] == -2)
    dp[to] = -1;
  if (dp[to] == -1)
    dp[s] = -1;
  else if (dp[to] > 0)
    dp[s] = dp[to] + 1;
}
void output(int s) {
  if (flag[s])
    printf("%d\n", s);
  else {
    printf("%d ", s);
    output(e[s][0]);
  }
}
int main() {
  int n, v;
  cin >> n;
  for (int i = 0; i < 100005; i++) e[i].clear();
  for (int i = 1; i <= n; i++) scanf("%d", &flag[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &v);
    if (v != 0) e[v].push_back(i);
    dp[i] = -2;
    vis[i] = false;
  }
  int ans = 0, pos = 0;
  for (int i = 1; i <= n; i++) {
    dfs(i);
    if (dp[i] > ans) {
      ans = dp[i];
      pos = i;
    }
  }
  printf("%d\n", ans);
  output(pos);
  return 0;
}
