#include<bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
const int MAX = 2e6 + 15;
const ll INF = 5e18 + 50;
#define fr first
#define sc second
ll dp[MAX], ans;
bool ex[MAX];
vector<ll> adj[MAX], w[MAX];
void calcdp(int u, int p){
if(adj[u].size() == 1){ dp[u] = 0; return; }
dp[u] = INF;
for(int i = 0; i < (int) adj[u].size(); i++){
ll 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<ll, ll> f1 = {INF, INF}, f2 = {INF, INF};
for(int i = 0; i < (int) adj[u].size(); i++){
int v = adj[u][i], c = w[u][i];
if(v == p) continue;
pair<ll, ll> cur = {dp[v] + c, v};
if(cur.fr < f1.fr){ swap(f1, f2); swap(cur, f1); }
else if(cur.fr < f2.fr){ swap(f2, cur); }
}
if(f2.sc == INF) return;
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]);
}
calcdp(0, -1);
dfs(0, -1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
94156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
94156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
94156 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |