#include<bits/stdc++.h>
using namespace std ;
#define F first
#define S second
const int N = 1e5+5 ;
int n , k , color[N] , par[N] , deep[N] , in[N] , out[N] , t ;
vector<int> child[N] , cpos[N] , dcnt[N] ;
pair<int,int> ans ;
void dfs(int node){
in[node]=++t ;
dcnt[deep[node]].push_back(in[node]) ;
for(int i:child[node]) deep[i]=deep[node]+1 , dfs(i) ;
out[node]=++t ;
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) ;
cin >> n >> k ; par[0] = -1 ;
for(int i=0 ; i<n ; i++) cin >> color[i] , cpos[color[i]].push_back(i) ;
for(int i=1 ; i<n ; i++) cin >> par[i] , child[par[i]].push_back(i) ;
dfs(0) ;
for(int i=0 ; i<k ; i++){
for(int j:cpos[i]){
map<int,int> mp1 , mp2 , mp3 ; // deep , not in subtree same color/subtree sum/subtree same color
for(int l:cpos[i]){
if(deep[l]<=deep[j]) continue ;
// is l belongs to j's subtree (if in[j]<in[l] then is)
// search in[j] <= dcnt[deep[l]][...] <= out[j] is the size of deep = l in subtree j
// dcnt[deep[l]] is the size of deep = l in all tree
int cur1 = upper_bound(dcnt[deep[l]].begin(),dcnt[deep[l]].end(),out[j])-dcnt[deep[l]].begin() ;
int cur2 = lower_bound(dcnt[deep[l]].begin(),dcnt[deep[l]].end(),in[j])-dcnt[deep[l]].begin() ;
mp2[deep[l]]=cur1-cur2 ;
if(in[j]<in[l] && out[l]<out[j]) mp3[deep[l]]++ ;
else mp1[deep[l]]++ ;
}
pair<int,int> temp = {1,0} ;
for(auto it:mp2){
temp.F+=mp3[it.F]+min(mp2[it.F]-mp3[it.F],mp1[it.F]) ;
temp.S+=min(mp2[it.F]-mp3[it.F],mp1[it.F]) ;
}
temp.S*=-1 ;
ans=max(ans,temp) ;
}
}
cout << ans.F << ' ' << -ans.S << '\n' ;
return 0 ;
}