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;
typedef long long ll;
int n, m;
vector<pair<int, int> > adj[100005];
priority_queue<ll> dist[100005];
ll ans[100005];
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
n = N; m = M;
for (int i = 0; i < m; i++) {
adj[R[i][0]].emplace_back(R[i][1], L[i]);
adj[R[i][1]].emplace_back(R[i][0], L[i]);
}
priority_queue<pair<ll, int> > pq;
memset(ans, 0x3f, sizeof(ans));
for (int i = 0; i < K; i++) {
dist[P[i]].push(0);
dist[P[i]].push(0);
pq.push({ 0, P[i] });
ans[P[i]] = 0;
}
while (!pq.empty()) {
ll cost = -pq.top().first;
int now = pq.top().second;
pq.pop();
if (ans[now]< cost)continue;
for (auto &e : adj[now]) {
int there = e.first;
int weight = e.second;
dist[there].push(cost + weight);
while (dist[there].size() > 2)dist[there].pop();
if (dist[there].size() == 2 && dist[there].top() < ans[there]) {
ans[there] = dist[there].top();
pq.push({ -dist[there].top(),there });
}
}
}
return ans[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... |