/**
* 输入数组的元素只能为 1或-1
* 求解乘积为1的子串
* 4
* 1 1 -1 -1
* 10
* // 前缀积
* public static void main(String[] args) {
* Scanner sc = new Scanner(System.in);
* int n = sc.nextInt();
* int[] nums = new int[n];
* for (int i = 0; i < n; i++) nums[i] = sc.nextInt();
* // 前缀积 [0, i]
* for (int i = 1; i < n; i++) nums[i] *= nums[i-1];
*
* int ans = 0;
* for (int i = 0; i < n; i++) {
* for (int j = i; j < n; j++) {
* if (nums[j] * (i > 0? nums[i-1]: 1) == 1) ans ++;
* }
* }
* System.out.println(ans);
* }
*
*/
/**
* n个房间 m秒
* 接下来m个数字代表第i秒 炸弹在哪个房间爆炸
* dp[i][j]表示第i秒在第j个房间所消耗的能量
* 2 4
* 2 1 1 2
* 2
*
* 3 10
* 2 3 1 3 2 1 1 2 3 1
*
* static int inf = (int)(1e9+5);
* public static void main(String[] args) {
* Scanner sc = new Scanner(System.in);
* int n = sc.nextInt();
* int m = sc.nextInt();
* int[] arr = new int[m+1];
* for (int i = 1; i <= m; i++) arr[i] = sc.nextInt();
* int[][] dp = new int[m+1][n+1];
* for (int i = 0; i <= m; i++) Arrays.fill(dp[i], inf);
* dp[0][1] = 0;
* for (int i = 1; i <= m; i++) {
* for (int j = 1; j <= n; j++) {
* if (arr[i] == j) dp[i][j] = inf;
* else dp[i][j] = Math.min(dp[i][j], Math.min(dp[i-1][j], dp[i-1][arr[i]] + 1)); // 不跳 or 跳
* }
* }
* Arrays.sort(dp[m]);
* System.out.println(dp[m][0]);
* }
*/
/**
* 节点范围n, 1 <=n<= 10000
* 邻接表建图
* 6
* 1 0 1 1 0 0 0为白色节点 1为黑色节点
* 0 1 2 1 4 4
* 3 2
* 若白色节点 没有子节点或者至少有一个黑色节点 则为好节点
* 若黑色节点 没有子节点或者所有节点全为白色节点 则为好节点
*/
public class Main {
static int N = 10005, M = 2 * 10005;
static int[] head = new int[N];
static int[] edge = new int[M];
static int[] next = new int[M];
static int root, r1, r2;
static int idx = 0;
static void add(int x, int y) { // x -> y 头插法
edge[idx] = y;
next[idx] = head[x];
head[x] = idx++;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] color = new int[n+1];
for (int i = 1; i <= n; i++) color[i] = sc.nextInt();
Arrays.fill(head, -1);
for (int i = 1; i <= n; i++) {
int from = sc.nextInt();
if (from == 0) root = i;
else add(from ,i);
}
dfs(color, root);
System.out.println(r1 + " " + r2);
}
public static void dfs(int[] color, int node) {
// 处理当前节点
if (color[node] == 0) { // 如果是白色节点
int size = 0, black = 0;
for (int i = head[node]; i != -1; i = next[i]) {
size++;
int to = edge[i];
if (color[to] == 1) black++;
}
if (size == 0 || black >= 1) r1++;
} else { // 如果为黑色节点
int size = 0, white = 0;
for (int i = head[node]; i != -1; i = next[i]) {
size ++;
int to = edge[i];
if (color[to] == 0) white++;
}
if (size == 0 || white == size) r2++;
}
// 处理子节点
for (int i = head[node]; i != -1; i = next[i]) {
int to = edge[i];
dfs(color, to);
}
}
}