#include using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; if (N == 1) { cout << 0 << endl; return 0; } vector> adj(N, set()); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; adj[a].insert(b); adj[b].insert(a); } vector C(M); for (int i = 0; i < M; i++) { cin >> C[i]; } vector d(N, -1); queue> q; for (int i = 0; i < M; i++) { q.emplace(C[i] - 1, 0); } while (!q.empty()) { int n = q.front().first; int dist = q.front().second; q.pop(); if (d[n] != -1) continue; d[n] = dist; for (auto& x : adj[n]) { q.emplace(x, dist + 1); } } for (int i = 0; i < N; i++) { cout << d[i] << endl; } int ans = 0; int t = 0; priority_queue, vector>, greater<>> pq; for (int i = 0; i < N; i++) { if (adj[i].size() == 1) { pq.emplace(d[i], i); } } while (!pq.empty()) { if (pq.empty()) break; int a = pq.top().first; int b = pq.top().second; pq.pop(); if (t >= a) continue; ans++; t++; int p = *adj[a].begin(); adj[p].erase(a); if (adj[p].size() == 1) { pq.emplace(d[p], p); } } cout << ans << endl; }