#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
vector<int> v[maxn];
int color[maxn];
int lv[maxn];
int dpth[maxn];
int level[maxn][maxn];
int node[maxn];
int mxc[maxn];
int mx = 0;
void dfs(int nd, int d) {
dpth[nd] = d;
mx = max(mx, d);
level[d][color[nd]]++;
for(auto i : v[nd]) {
dfs(i, d + 1);
}
}
void count(int nd, int cl) {
node[dpth[nd]]++;
if(color[nd] == cl) {
mxc[dpth[nd]]++;
}
for(auto i : v[nd]) {
count(i, cl);
}
}
int main() {
int n, k;
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> color[i];
for(int i = 1; i < n; i++) {
int b;
cin >> b;
v[b].push_back(i);
}
dfs(0, 0);
int mxcl = 0;
int updt = 1e9;
for(int i = 0; i < n; i++) {
for(int d = 0; d <= mx; d++) {
node[d] = 0;
mxc[d] = 0;
}
int cl = color[i];
count(i, cl);
int currcl = 0;
int currupdt = 0;
for(int d = dpth[i]; d <= mx; d++) {
if(node[d] == 0) continue;
int m = min(node[d], level[d][cl]);
currcl += m;
currupdt += (m - mxc[d]);
}
if(currcl > mxcl) {
mxcl = currcl;
updt = currupdt;
} else if(currcl == mxcl) {
if(currupdt < updt) updt = currupdt;
}
}
cout << mxcl << " " << updt << endl;
}