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 <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;
}
}
}
long long solve() {
for (int i = 0; i < n; ++i) {
dfs1(i, i, i);
}
memset(dp, 0x3f, sizeof dp);
dfs2(0, 0);
return dp[0][1];
}
};
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
n = N;
m = M;
k = K;
for (int i = 0; i < m; ++i) {
int u = R[i][0], v = R[i][1], w = L[i];
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;
}
long long ans = sub1::solve();
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |