#include <bits/stdc++.h>
using namespace std;
bool vis[100010], b[100010];
vector<int> adj[100010];
multimap<int, int> a;
int dfs(int i) {
  vis[i] = 1;
  if (adj[i].size())
    if (!vis[adj[i][0]]) return dfs(adj[i][0]) + 1;
  return 1;
}
void dfs2(int i) {
  vis[i] = 1;
  if (adj[i].size())
    if (!vis[adj[i][0]]) dfs2(adj[i][0]);
  cout << i << " ";
}
int main() {
  int n, i, x;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> x;
    if (x == 1) b[i] = 1;
  }
  for (i = 1; i <= n; i++) {
    cin >> x;
    a.insert(pair<int, int>(x, i));
  }
  for (i = 1; i <= n; i++) {
    if (a.count(i) > 1) a.erase(i);
  }
  for (i = 1; i <= n; i++) {
    if (a.count(i) == 1) adj[a.find(i)->second].push_back(i);
  }
  adj[0].clear();
  int m = -1, mp;
  for (i = 1; i <= n; i++) {
    if (b[i]) {
      memset(vis, 0, sizeof(vis));
      int ma = dfs(i);
      if (m < ma) {
        m = ma;
        mp = i;
      }
    }
  }
  cout << m << endl;
  memset(vis, 0, sizeof(vis));
  dfs2(mp);
}
