#include <bits/stdc++.h>
using namespace std;
int val[100005];
vector<int> edge[100005];
int vis[100005];
vector<int> path[100005];
int n;
int a;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &val[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    if (a) {
      edge[i].push_back(a);
      vis[a]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (val[i]) {
      path[i].push_back(i);
      if (edge[i].size() == 0) {
        continue;
      }
      int pos = edge[i][0];
      while (true) {
        if (val[pos] == 1) {
          break;
        }
        if (vis[pos] > 1) {
          break;
        }
        if (edge[pos].size() == 0) {
          path[i].push_back(pos);
          break;
        }
        path[i].push_back(pos);
        pos = edge[pos][0];
      }
    }
  }
  int maxn = -1;
  for (int i = 1; i <= n; i++) {
    maxn = max((int)path[i].size(), maxn);
  }
  for (int i = 1; i <= n; i++) {
    if (path[i].size() == maxn) {
      printf("%d\n", maxn);
      for (int j = path[i].size() - 1; j >= 0; j--) {
        printf(j == path[i].size() - 1 ? "%d" : " %d", path[i][j]);
      }
      printf("\n");
      break;
    }
  }
  return 0;
}
