#include <bits/stdc++.h>
using namespace std;
int a[111111], b[111111];
bool used[111111];
int one[111111];
vector<int> answer;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  memset(one, 0, sizeof(one));
  for (int i = 1; i <= n; i++) one[b[i]]++;
  for (int i = 1; i <= n; i++)
    if (one[i] != 1) one[i] = 0;
  int ans = 0;
  int num = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) {
      int cnt = 1;
      int cur = i;
      while (b[cur] != 0 && a[b[cur]] == 0 && one[b[cur]] == 1) {
        cur = b[cur];
        cnt++;
      }
      if (cnt > ans) {
        ans = cnt;
        num = i;
      }
    }
  memset(used, false, sizeof(used));
  cout << ans << endl;
  used[num] = true;
  answer.push_back(num);
  num = b[num];
  while (num != 0 && a[num] == 0 && one[num] == 1) {
    used[num] = true;
    answer.push_back(num);
    num = b[num];
  }
  for (int i = 0; i < answer.size(); i++)
    cout << answer[answer.size() - 1 - i] << " ";
  cout << endl;
  return 0;
}
