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 MAX_N = 100000;
const int INF = 1000000001;
vector<pair<int, int> > graph[MAX_N];
int dp[MAX_N];
bool proc[MAX_N];
void dfs(int nod) {
if(!proc[nod] && dp[nod] == INF) {
int best[2];
proc[nod] = true;
best[0] = best[1] = INF;
for(auto it: graph[nod]) {
dfs(it.first);
int cost = dp[it.first] + it.second;
if(cost <= best[0]) {
best[1] = best[0];
best[0] = cost;
} else if(cost <= best[1])
best[1] = cost;
}
dp[nod] = best[1];
proc[nod] = false;
}
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
for(int i = 0; i < M; ++i) {
graph[R[i][0]].push_back(make_pair(R[i][1], L[i]));
graph[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
for(int i = 0; i < N; ++i)
dp[i] = INF;
for(int i = 0; i < K; ++i) {
dp[P[i]] = 0;
proc[P[i]] = true;
}
dfs(0);
return dp[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |