# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984857 | 54skyxenon | Crocodile's Underground City (IOI11_crocodile) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/IOI11_crocodile
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<map<int, int>> graph;
vector<bool> is_exit;
vector<bool> visited;
int dfs(int curr) {
if (is_exit[curr]) {
return 0;
}
vector<int> distances;
for (auto [nei, weight] : graph[curr]) {
if (!visited[nei]) {
visited[nei] = true;
distances.push_back(weight + dfs(nei));
}
}
sort(distances.begin(), distances.end());
return distances[1];
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
graph.resize(n);
for (int i = 0; i < m; i++) {
int u, v, w;
cin >> u >> v >> w;
graph[u][v] = graph[v][u] = w;
}
is_exit.resize(n);
visited.resize(n);
for (int i = 0; i < k; i++) {
int p;
cin >> p;
is_exit[p] = true;
}
visited[0] = true;
cout << dfs(0) << '\n';
}