#include <bits/stdc++.h>   using namespace std;   int morh[100001], parent[100001], pos[100001], temp = 0, ans = 0;   int calculate(int i) {     int posi = i, ans = 0;     while (posi != 0) {       if (pos[posi] > 1)         break;       else {         posi = parent[posi];         ans++;       }     }     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &morh[i]);     }     for (int i = 1; i <= n; i++) {       scanf( %d , &parent[i]);       pos[parent[i]]++;     }     int temp2;     for (int i = 1; i <= n; i++) {       if (morh[i] == 1) {         temp2 = calculate(i);         if (temp2 > ans) {           ans = temp2;           temp = i;         }       }     }     temp2 = ans;     int give_ans[ans], i = 0;     for (int j = 0; j < temp2; j++) {       give_ans[i] = temp;       i++;       temp = parent[temp];     }     printf( %d n , ans);     for (int i = ans - 1; i >= 0; i--) printf( %d  , give_ans[i]);     printf(  n );   }   