#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
#define ll long long
#define endl '\n'
int n,k,lang[100005],fa[100005],dep[100005],depmax[2005][2005];
int have[2005],empt[2005],dm[100005],dans,dop,tdm[100005];
vector<int> go[100005];
bool anc[100005];
void dfs(int ps){
if(anc[fa[ps]]) anc[ps]=1;
dep[ps]=dep[fa[ps]]+1;
for(auto g:go[ps]){
if(g==fa[ps]) continue;
if(lang[ps]!=lang[1]) anc[g]=1;
dfs(g);
}
}
void dfs2(int ps,int id){
have[dep[ps]]+=(lang[ps]==id);
empt[dep[ps]]++;
for(auto g:go[ps]){
if(g==fa[ps]) continue;
dfs2(g,id);
}
}
void dfs3(int ps,int id){
if(lang[ps]!=id&&dm[dep[ps]]){
dm[dep[ps]]--;
dop++;
dans++;
}
if(lang[ps]==id&&dm[dep[ps]]) dm[dep[ps]]--,dans++;
if(lang[ps]==id&&dm[dep[ps]]==0) dop--;
for(auto g:go[ps]){
if(g==fa[ps]) continue;
dfs3(g,id);
}
}
void clean(int ps){
dm[dep[ps]]=tdm[dep[ps]];
for(auto g:go[ps]){
if(g==fa[ps]) continue;
clean(g);
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>lang[i],lang[i]++;
bool ch=1;
for(int i=2;i<=n;i++){
cin>>fa[i];
fa[i]++;
go[fa[i]].push_back(i);
if(fa[i]!=i-1) ch=0;
}
dfs(1);
if(ch){
int cnt[100005];
memset(cnt,0,sizeof(cnt));
int maxx=0;
for(int i=n;i>=1;i--){
cnt[lang[i]]++;
maxx=max(maxx,cnt[lang[i]]);
}
cout<<maxx<<' '<<0<<endl;
}
else if(k<=2){
int cnt=0;
for(int i=1;i<=n;i++){
if(lang[i]==lang[1]) cnt++;
else dm[dep[i]]++,tdm[dep[i]]++;
}
int maxx=cnt,op=0;
for(int i=1;i<=n;i++)
if(lang[i]!=lang[1]&&!anc[i]){
// cout<<"GO:"<<i<<endl;
dans=0,dop=0;
dfs3(i,lang[i]);
// cout<<dans<<' '<<dop<<endl;
clean(i);
if(dans>maxx){
maxx=dans;
op=dop;
}
else if (dans==maxx) op=min(op,dop);
}
cout<<maxx<<' '<<op<<endl;
}
else{
for(int i=1;i<=n;i++) depmax[lang[i]][dep[i]]++;
int maxx=0,op=0;
for(int i=1;i<=n;i++){
memset(have,0,sizeof(have));
memset(empt,0,sizeof(empt));
// cout<<"ROOTED:"<<i<<endl;
dfs2(i,lang[i]);
int ans=0,top=0;
for(int j=1;j<=n;j++){
int t=min(depmax[lang[i]][j],empt[j]);
ans+=t;
top+=t-have[j];
// cout<<"depth:"<<j<<' '<<t<<endl;
}
if(ans>maxx) maxx=ans,op=top;
else if(ans==maxx) op=min(op,top);
}
cout<<maxx<<' '<<op<<endl;
}
return 0;
}
/*
32 2
0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0
0 1 1 0 0 1 4 4 4 5 5 6 6 7 7 7 10 10 10 11 20 20 0 31 31 31 24 24 24 23 23
*/