# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709634 | therealpain | 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.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
vector <pair <int, int>> adj[N];
bool special[N];
int n, m, k;
namespace sub1 {
long long dist[1000][1000];
long long dp[1000][2];
void dfs1(int u, int p, int root) {
for (auto [v, w] : adj[u]) {
if (v == p || v == root) continue;
dist[root][v] = dist[root][u] + w;
dfs1(v, u, root);
}
}
void dfs2(int u, int p) {
if (special[u] == true) {
dp[u][0] = dp[u][1] = 0;
return;
}
for (auto [v, w] : adj[u]) {
if (v == p) continue;
dfs2(v, u);
if (dp[u][0] > dp[v][1] + w) {
dp[u][1] = dp[u][0];
dp[u][0] = dp[v][1] + w;
} else if (dp[u][1] > dp[v][1] + w) {
dp[u][1] = dp[v][1] + w;
}
}
}
void solve() {
for (int i = 0; i < n; ++i) {
dfs1(i, i, i);
}
memset(dp, 0x3f, sizeof dp);
dfs2(0, 0);
cout << dp[0][1];
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 0; i < m; ++i) {
int u, v, w; cin >> u >> v >> w;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
for (int i = 0; i < k; ++i) {
int x; cin >> x;
special[x] = true;
}
sub1::solve();
}