#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using P = pair; const long long LM = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(0); int n, q, c; cin >> n >> q >> c; vector> edge(n); for (int i = 0; i < n - 1; ++i) { int u, v, l; cin >> u >> v >> l; --u; --v; edge[u].emplace_back(l, v); edge[v].emplace_back(l, u); } vector x(q); for (int i = 0; i < q; ++i) { cin >> x[i]; --x[i]; } vector> dist(n, vector(n, LM)); for (int i = 0; i < n; ++i) { queue que; dist[i][i] = 0; que.push(i); while (!que.empty()) { int p = que.front(); que.pop(); for (auto& e : edge[p]) { if (dist[i][e.second] > dist[i][p] + e.first) { dist[i][e.second] = dist[i][p] + e.first; que.push(e.second); } } } } vector dp(n, LM); dp[x[0]] = 0; for (int i = 1; i < q; ++i) { vector nex(n, LM); for (int j = 0; j < n; ++j) { nex[j] = dp[j] + min(dist[x[i - 1]][x[i]], c + dist[j][x[i]]); } for (int k = 0; k < n; ++k) { if (dist[x[i - 1]][k] + dist[k][x[i]] != dist[x[i - 1]][x[i]]) continue; for (int j = 0; j < n; j++) { long d = min(dist[x[i - 1]][k], c + dist[j][k]) + dist[k][x[i]]; nex[k] = min(nex[k], dp[j] + d); } } dp = nex; } long long ans = LM; for (int i = 0; i < n; ++i) { ans = min(ans, dp[i]); } cout << ans << '\n'; return 0; }