#include <bits/stdc++.h>
using namespace std;
int dfs(int node, vector<vector<int>>& g, vector<int>& bad, vector<int>& path) {
  if (bad[node] > 1) return 0;
  int answer = 1;
  if (g[node].size() != 0) answer += dfs(g[node][0], g, bad, path);
  path.push_back(node);
  return answer;
}
int main() {
  int n, x;
  while (cin >> n) {
    vector<int> kind(n);
    vector<int> bad(n);
    vector<vector<int>> g(n);
    for (auto& i : kind) cin >> i;
    for (int i = 0; i < n; ++i) {
      cin >> x;
      if (x == 0) continue;
      x--;
      g[i].push_back(x);
      bad[x]++;
    }
    int mmax = 0;
    vector<int> answer;
    for (int i = 0; i < n; ++i) {
      if (kind[i]) {
        vector<int> answert;
        int tmp = dfs(i, g, bad, answert);
        if (tmp > mmax) {
          mmax = tmp;
          answer = answert;
        }
      }
    }
    cout << answer.size() << endl;
    for (int i = 0; i < answer.size(); ++i) {
      if (i) cout << " ";
      cout << answer[i] + 1;
    }
    cout << endl;
  }
  return 0;
}
