#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
vector<int> adj[MAXN];
bool isPho[MAXN];
bool valid[MAXN];
int N, M;
void prune(int node, int parent) {
valid[node] = isPho[node];
for (int neighbor : adj[node]) {
if (neighbor != parent) {
prune(neighbor, node);
valid[node] = valid[node] || valid[neighbor];
}
}
}
pair<int, int> dfs(int node, int parent) {
pair<int, int> farthest = {0, node};
for (int neighbor : adj[node]) {
if (neighbor != parent && valid[neighbor]) {
pair<int, int> result = dfs(neighbor, node);
result.first += 1;
if (result.first > farthest.first) {
farthest = result;
}
}
}
return farthest;
}
int main() {
cin >> N >> M;
vector<int> pho_restaurants(M);
for (int i = 0; i < M; i++) {
cin >> pho_restaurants[i];
isPho[pho_restaurants[i]] = true;
}
for (int i = 0; i < N - 1; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
prune(pho_restaurants[0], -1);
int start = pho_restaurants[0];
while (!valid[start]) start++;
pair<int, int> first_dfs = dfs(start, -1);
int farthest_node = first_dfs.second;
pair<int, int> second_dfs = dfs(farthest_node, -1);
int longest_path = second_dfs.first;
int pruned_node_count = 0;
for (int i = 0; i < N; i++) {
if (valid[i]) pruned_node_count++;
}
int result = 2 * (pruned_node_count - 1) - longest_path;
cout << result << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTUFYTiA9IDEwMDAwNTsKdmVjdG9yPGludD4gYWRqW01BWE5dOwpib29sIGlzUGhvW01BWE5dOwpib29sIHZhbGlkW01BWE5dOwppbnQgTiwgTTsKCnZvaWQgcHJ1bmUoaW50IG5vZGUsIGludCBwYXJlbnQpIHsKICAgIHZhbGlkW25vZGVdID0gaXNQaG9bbm9kZV07CiAgICBmb3IgKGludCBuZWlnaGJvciA6IGFkaltub2RlXSkgewogICAgICAgIGlmIChuZWlnaGJvciAhPSBwYXJlbnQpIHsKICAgICAgICAgICAgcHJ1bmUobmVpZ2hib3IsIG5vZGUpOwogICAgICAgICAgICB2YWxpZFtub2RlXSA9IHZhbGlkW25vZGVdIHx8IHZhbGlkW25laWdoYm9yXTsKICAgICAgICB9CiAgICB9Cn0KCnBhaXI8aW50LCBpbnQ+IGRmcyhpbnQgbm9kZSwgaW50IHBhcmVudCkgewogICAgcGFpcjxpbnQsIGludD4gZmFydGhlc3QgPSB7MCwgbm9kZX07IAogICAgZm9yIChpbnQgbmVpZ2hib3IgOiBhZGpbbm9kZV0pIHsKICAgICAgICBpZiAobmVpZ2hib3IgIT0gcGFyZW50ICYmIHZhbGlkW25laWdoYm9yXSkgewogICAgICAgICAgICBwYWlyPGludCwgaW50PiByZXN1bHQgPSBkZnMobmVpZ2hib3IsIG5vZGUpOwogICAgICAgICAgICByZXN1bHQuZmlyc3QgKz0gMTsgCiAgICAgICAgICAgIGlmIChyZXN1bHQuZmlyc3QgPiBmYXJ0aGVzdC5maXJzdCkgewogICAgICAgICAgICAgICAgZmFydGhlc3QgPSByZXN1bHQ7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gZmFydGhlc3Q7Cn0KCmludCBtYWluKCkgewogICAgY2luID4+IE4gPj4gTTsKICAgIHZlY3RvcjxpbnQ+IHBob19yZXN0YXVyYW50cyhNKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTTsgaSsrKSB7CiAgICAgICAgY2luID4+IHBob19yZXN0YXVyYW50c1tpXTsKICAgICAgICBpc1Bob1twaG9fcmVzdGF1cmFudHNbaV1dID0gdHJ1ZTsKICAgIH0KICAgIGZvciAoaW50IGkgPSAwOyBpIDwgTiAtIDE7IGkrKykgewogICAgICAgIGludCB1LCB2OwogICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgYWRqW3VdLnB1c2hfYmFjayh2KTsKICAgICAgICBhZGpbdl0ucHVzaF9iYWNrKHUpOwogICAgfQogICAgcHJ1bmUocGhvX3Jlc3RhdXJhbnR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