#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int Max = 1e5 + 10;
int n, s;
int type[Max], d[Max];
vector<int> edge[Max];
stack<int> path[Max];
bool vis[Max];
void dfs() {
  for (int i = 1; i <= n; i++) {
    if (type[i] == 1) {
      path[i].push(i);
      if (edge[i].size() == 0) continue;
      int now = edge[i][0];
      while (true) {
        if (d[now] > 1 || type[now] == 1) {
          break;
        }
        path[i].push(now);
        if (edge[now].size() == 0) break;
        now = edge[now][0];
      }
    }
  }
  int dis = 0;
  int id = -1;
  for (int i = 1; i <= n; i++) {
    if (type[i] == 1) {
      if (dis < path[i].size()) {
        dis = path[i].size();
        id = i;
      }
    }
  }
  printf("%d\n", dis);
  while (!path[id].empty()) {
    printf("%d ", path[id].top());
    path[id].pop();
  }
  printf("\n");
}
int main() {
  while (scanf("%d", &n) != EOF) {
    s = -1;
    for (int i = 1; i <= n; i++) {
      scanf("%d", type + i);
      if (type[i] == 1 && s == -1) s = i;
      while (!path[i].empty()) path[i].pop();
      d[i] = 0;
      edge[i].clear();
    }
    for (int v = 1; v <= n; v++) {
      int u;
      scanf("%d", &u);
      if (u != 0) {
        edge[v].push_back(u);
        d[u]++;
      }
    }
    dfs();
  }
  return 0;
}
