# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
483901 | evenvalue | 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 "crocodile.h"
#include <vector>
using namespace std;
struct edge {
int x;
int y;
int w;
};
class solution {
const int kInf = 1e9 + 10;
const int n;
const int m;
const vector<edge> edges;
const int k;
const vector<int> end;
vector<vector<pair<int, int>>> g;
vector<int> dp;
int dfs(const int x, const int p) {
if (dp[x] == 0) return 0;
int mn = kInf, mn2 = kInf;
for (const auto &[y, w] : g[x]) {
if (y == p) continue;
const int cur = dfs(y, x) + w;
if (cur < mn) {
mn2 = mn;
mn = cur;
} else {
mn2 = min(mn2, cur);
}
}
return (dp[x] = mn2);
}
public:
explicit solution(const int n, const vector<edge> &edges, const vector<int> &end) : n(n), m(edges.size()), edges(edges), k(end.size()), end(end), g(n), dp(n, kInf) {
for (const auto &[x, y, w] : edges) {
g[x].emplace_back(y, w);
g[y].emplace_back(x, w);
}
for (const int x : end) dp[x] = 0;
}
int main() {
return dfs(0, -1);
}
};
int travel_plan(const int N, const int M, const int Edges[][2], const int Cost[], const int K, const int P[]) {
vector<edge> edges(M);
for (int i = 0; i < M; i++) {
edges[i].x = Edges[i][0];
edges[i].y = Edges[i][1];
edges[i].w = Cost[i];
}
vector<int> end(K);
for (int i = 0; i < K; i++) {
end[i] = P[i];
}
solution s(N, edges, end);
return s.main();
}