# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
337013 | r_v_n | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
using namespace std;
#include <bits/stdc++.h>
#define ll long long
int dp[100001];
int n;
int m, k;
vector<pair<int, int>> adj[100001];
map<int, int> is;
void dfs(int v, int p = -1)
{
if (adj[v].size() == 1)
{
if (is[v])
dp[v] = 0;
else
dp[v] = 1e9;
return;
}
vector<int> store;
for (auto it : adj[v])
{
if (it.first == p)
continue;
dfs(it.first, v);
store.push_back(dp[it.first] + it.second);
}
sort(store.begin(), store.end());
dp[v] = store[1];
}
void solve()
{
cin >> n >> m >> k;
for (int i = 0; i <= n; i++)
{
adj[i].clear();
dp[i] = 0;
}
is.clear();
for (int i = 0; i < m; i++)
{
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
for (int i = 0; i < k; i++)
{
int a;
cin >> a;
is[a] = 1;
}
dfs(0);
cout << dp[0] << endl;
}
int main()
{
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t = 1;
//cin >> t;
while (t--)
solve();
return 0;
}