#include <bits/stdc++.h>
using namespace std;
unordered_set<long long int> adj[100005], adj1[100005];
vector<bool> vis(100005, false);
vector<long long int> dist(100005, -1), en(100005, 0);
long long int k;
vector<long long int> par(100005, -1);
void bfs(long long int s, bool flag = false) {
  queue<long long int> q;
  q.push(s);
  vis[s] = true;
  dist[s] = 1;
  par[s] = -1;
  while (!q.empty()) {
    s = q.front();
    if (flag) {
      cout << s << " ";
      if (dist[s] == k) return;
    }
    q.pop();
    for (auto ch : adj[s]) {
      if (dist[ch] == -1 && en[ch] == 1) {
        dist[ch] = 1 + dist[s];
        q.push(ch);
        vis[ch] = true;
        par[ch] = s;
      }
    }
  }
}
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> tp(n + 1);
  for (long long int i = 1; i < n + 1; i++) cin >> tp[i];
  for (long long int i = 1; i < n + 1; i++) {
    long long int u;
    cin >> u;
    if (u == 0) continue;
    adj[i].insert(u);
    en[u]++;
  }
  for (long long int i = 1; i < n + 1; i++) {
    if (!vis[i] && tp[i] == 1) bfs(i);
  }
  k = 0;
  long long int src;
  for (long long int i = 1; i < n + 1; i++) {
    if (k < dist[i]) {
      k = dist[i];
      src = i;
    }
  }
  vis.assign(vis.size(), false);
  dist.assign(dist.size(), -1);
  cout << k << "\n";
  while (src != -1) {
    cout << src << " ";
    src = par[src];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
