|
|
|
@ -3,7 +3,7 @@ using namespace std;
|
|
|
|
|
const int N = 500010, M = N << 1;
|
|
|
|
|
#define int long long
|
|
|
|
|
|
|
|
|
|
int n, K;
|
|
|
|
|
int n, m;
|
|
|
|
|
|
|
|
|
|
// 链式前向星
|
|
|
|
|
int e[M], h[N], idx, w[M], ne[M];
|
|
|
|
@ -14,9 +14,9 @@ void add(int a, int b, int c = 0) {
|
|
|
|
|
int pos[N];
|
|
|
|
|
int sz[N], g[N], f[N];
|
|
|
|
|
int len[N], id[N], slen[N];
|
|
|
|
|
|
|
|
|
|
void dfs1(int u, int fa) {
|
|
|
|
|
if (pos[u]) sz[u] = 1;
|
|
|
|
|
|
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
|
|
|
int v = e[i];
|
|
|
|
|
if (v == fa) continue;
|
|
|
|
@ -32,13 +32,14 @@ void dfs1(int u, int fa) {
|
|
|
|
|
sz[u] += sz[v];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dfs2(int u, int fa) {
|
|
|
|
|
for (int i = h[u]; ~i; i = ne[i]) {
|
|
|
|
|
int v = e[i];
|
|
|
|
|
if (v == fa) continue;
|
|
|
|
|
if (!sz[v])
|
|
|
|
|
f[v] = f[u] + 2 * w[i], len[v] = len[u] + w[i];
|
|
|
|
|
else if (K - sz[v]) {
|
|
|
|
|
else if (m - sz[v]) {
|
|
|
|
|
f[v] = f[u];
|
|
|
|
|
if (id[u] != v && len[v] < len[u] + w[i])
|
|
|
|
|
slen[v] = len[v], len[v] = len[u] + w[i], id[v] = u;
|
|
|
|
@ -57,13 +58,13 @@ signed main() {
|
|
|
|
|
// 初始化链式前向星
|
|
|
|
|
memset(h, -1, sizeof h);
|
|
|
|
|
|
|
|
|
|
cin >> n >> K;
|
|
|
|
|
cin >> n >> m;
|
|
|
|
|
for (int i = 1; i < n; i++) {
|
|
|
|
|
int a, b, c;
|
|
|
|
|
cin >> a >> b >> c;
|
|
|
|
|
add(a, b, c), add(b, a, c);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 1; i <= K; i++) {
|
|
|
|
|
for (int i = 1; i <= m; i++) {
|
|
|
|
|
int x;
|
|
|
|
|
cin >> x;
|
|
|
|
|
pos[x] = 1;
|
|
|
|
|