#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int travel_plan (int N, int M, int R[][2], int L[], int K, int P[]) {
vector<array<int, 2>> g[N];
for (int i = 0;i < M;i ++) {
g[R[i][0]].push_back({R[i][1], L[i]});
g[R[i][1]].push_back({R[i][0], L[i]});
}
priority_queue<array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> pq;
for(int i = 0;i < K;i ++) {
pq.push({0, P[i]});
pq.push({0, P[i]});
}
vector<ll> d[N];
while (pq.size() > 0) {
auto [cnt, node] = pq.top();
pq.pop();
if (d[node].size() < 2) {
d[node].push_back(cnt);
if (d[node].size() == 2) {
for (auto [ti, wi] : g[node]) {
pq.push({cnt + wi, ti});
}
}
}
}
// for (int j = 0;j < N;j ++) {
// cout << j << " || ";
// for (auto x : d[j]) cout << x << " ";
// cout << "\n";
// }
return d[0][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |