#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxN = 1005;
int dp[mxN][mxN], s[mxN], f[mxN], cost = 0, ans = 1e9, st, n, k;
vector<int> adj[mxN];
void dfs(int u = 1, int par = 0){
dp[u][s[u]] += 1;
for(auto it : adj[u]){
if(it ^ par){
dfs(it, u);
for(int j = 1; j <= k; ++j){
dp[u][j] += dp[it][j];
}
}
}
bool ok = 1;
for(int j = 1; j <= k; ++j){
if(dp[u][j] != 0 && dp[u][j] != f[j]){
ok = 0;
}
}
if(ok) {
dp[u][s[u]] = -1e9, cost += 1;
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> k;
for(int i = 1, u, v; i <= n - 1; ++i){
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; ++i){
cin >> s[i];
f[s[i]] += 1;
}
for(int i = 1; i <= n; ++i){
st = i, cost = 0;
for(int j = 1; j <= n; ++j){
for(int x = 1; x <= k; ++x){
dp[j][x] = 0;
}
}
dfs(i, -1);
ans = min(ans, cost - 1);
cout << i << " " << cost - 1 << "\n";
}
cout << max(0ll, ans) << "\n";
return 0;
}