#include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;

vector<int> adj[200200];
int D;
int cnt;

int dfs(int cur, int p=-1) {
    int mn=0, mx=0;
    for (auto &nxt : adj[cur]) {
        if (nxt == p) continue;
        int r = dfs(nxt, cur);
        mn = min(mn, r);
        mx = max(mx, r);
    }
    if (mx + mn >= 1) return mx - 1;
    if (mn == -D) {
        ++cnt;
        return D;
    }
    return mn - 1;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);

    int n,k; cin>>n>>k;
    for (int i=1; i<n; i++) {
        int a,b; cin>>a>>b;
        adj[a].pb(b); adj[b].pb(a);
    }
    int here = -1;
    for (int le=1,ri=n-1; le<=ri;) {
        D = le+ri>>1;
        cnt = 0;
        int r = dfs(1);
        if (r < 0) ++cnt;
        if (cnt <= k) {
            here = D;
            ri = D - 1;
        }
        else {
            le = D + 1;
        }
    }
    assert(~here);
    cout<<here<<'\n';
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
int n,c[100005],vis[100005],nowc[100005];
vector <int> g[100005];
vector <int> ans;
void dfs(int now)
{
	/*
	cout<<now<<endl;
	for(int i=1;i<=n;i++) cout<<vis[i]<<" ";
	puts("");
	for(int i=1;i<=n;i++) cout<<nowc[i]<<" ";
	puts("");
	system("pause");
	*/
	vis[now]=1;
	if(nowc[c[now]]==0) ans.pb(now);
	nowc[c[now]]++;
	for(int i=0;i<g[now].size();i++)
	{
		if(!vis[g[now][i]]) dfs(g[now][i]);
	}
	nowc[c[now]]--;
}
void solve()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>c[i];
	for(int i=1;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(1);
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++) cout<<ans[i]<<"\n";
}
signed main()
{
	int _=1;
	//cin>>_;
	while(_--) solve();
	return 0;
}