#include<bits/stdc++.h>
#include "crocodile.h"
using namespace std;
const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
#define fr first
#define sc second
int dp[MAX], ans;
bool ex[MAX];
vector<int> adj[MAX], w[MAX];
void calcdp(int u, int p){
if(adj[u].size() == 1){
if(ex[u]) dp[u] = 0;
else dp[u] = INF;
return;
}
dp[u] = INF;
for(int i = 0; i < (int) adj[u].size(); i++){
int v = adj[u][i], c = w[u][i];
if(v == p) continue;
calcdp(v, u);
dp[u] = min(dp[u], dp[v] + c);
}
}
void dfs(int u, int p){
pair<int, int> f1 = {INF, INF}, f2 = f1;
for(int i = 0; i < (int) adj[u].size(); i++){
int v = adj[u][i], c = w[u][i];
if(v == p) continue;
pair<int, int> cur = {dp[v] + c, v};
if(cur < f1){ swap(f1, f2); swap(cur, f1); }
else if(cur < f2){ swap(f2, cur); }
}
ans += f2.fr;
dfs(f2.sc, u);
}
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
for(int i = 0; i < m; i++){
int u = R[i][0], v = R[i][1];
adj[u].push_back(v);
adj[v].push_back(u);
w[u].push_back(L[i]);
w[v].push_back(L[i]);
}
for(int i = 0; i < k; i++)
ex[P[i]] = true;
calcdp(0, -1);
dfs(0, -1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
117 ms |
190884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
117 ms |
190884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
117 ms |
190884 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |