#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
vector<int> g[MAXN];
int cnt[MAXN];
int type[MAXN];
int dfs(int v) {
  int ans = -1;
  if (g[v].size() == 0) {
    if (type[v] == 1)
      return 1;
    else
      return -1;
  }
  for (size_t i = 0; i < g[v].size(); i++) ans = max(ans, dfs(g[v][i]));
  if (ans != -1) ans++;
  return ans;
}
vector<int> path;
bool print(int v, int lvl, int ans) {
  for (size_t i = 0; i < g[v].size(); i++)
    if (print(g[v][i], lvl + 1, ans)) {
      path.push_back(v);
      return true;
    }
  if (lvl == ans) {
    path.push_back(v);
    return true;
  } else
    return false;
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> type[i + 1];
  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if (v) {
      g[v].push_back(i + 1);
      cnt[i + 1]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (g[i].size() > 1) {
      for (int j = 0; j < g[i].size(); j++) cnt[g[i][j]]--;
      g[i].clear();
    }
  }
  int ans = -1, v = -1;
  for (int i = 1; i <= n; i++)
    if (cnt[i] == 0) {
      int ta = dfs(i);
      if (ta > ans) {
        ans = ta;
        v = i;
      }
    }
  cout << ans << endl;
  print(v, 1, ans);
  for (int i = path.size() - 1; i >= 0; i--) cout << path[i] << " ";
  cout << endl;
  return 0;
}
