#include using namespace std; #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = (n)-1; i >= 0; --i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; constexpr ll inf = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q, c; cin >> n >> q >> c; vector> to(n); rep(i, n - 1) { int u, v, l; cin >> u >> v >> l; --u, --v; to[u].emplace_back(v, l); to[v].emplace_back(u, l); } VVL dist(n, VL(n, inf)); rep(s, n) { VI vs{s}; dist[s][s] = 0; while(!vs.empty()) { int u = vs.back(); vs.pop_back(); for(auto [v, l]: to[u]) { if (dist[s][v] != inf) continue; dist[s][v] = dist[s][u] + l; vs.push_back(v); } } } VI x(q); rep(i, q) cin >> x[i], x[i]--; VL dp(n, inf); dp[x[0]] = 0; rep(i, q - 1) { VL ndp = dp; rep(u, n) ndp[u] += dist[x[i]][x[i+1]]; VL d(n, inf); priority_queue,vector>,greater>> q; auto push = [&](int v, ll c) { if (c < d[v]) { d[v] = c; q.emplace(c, v); } }; push(x[i], dp[x[i]]); rep(u, n) push(u, dp[u] + c); while(!q.empty()) { auto [cost, u] = q.top(); q.pop(); if (cost != d[u]) continue; for(auto [v, l]: to[u]) { push(v, cost + l); } } rep(u, n) chmin(ndp[u], d[u] + dist[u][x[i+1]]); dp = move(ndp); } ll ans = dp[x[q-1]]; cout << ans << endl; }