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 <vector>
#include <queue>
using namespace std;
using ll = long long;
ll dijkstra(vector<int> starts, vector<vector<pair<int, ll>>> adj)
{
int n = adj.size();
vector<pair<ll, ll>> dist(n, {1e12, 1e12});
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> pq;
vector<bool> used(n);
for (int i : starts)
{
dist[i].first = dist[i].second = 0;
pq.push({0, i});
}
while (!pq.empty())
{
int v = pq.top().second;
pq.pop();
if (used[v]) continue;
used[v] = true;
for (auto [u, w] : adj[v])
{
if (dist[u].first > dist[v].second + w)
{
dist[u].second = dist[u].first;
dist[u].first = dist[v].second + w;
if (dist[u].second != 1e12) pq.push({dist[u].second, u});
}
else if (dist[u].second > dist[v].second + w)
{
dist[u].second = dist[v].second + w;
pq.push({dist[u].second, u});
}
}
}
return dist[0].second;
}
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
vector<int> starts(k);
for (int i = 0; i < k; ++i) starts[i] = P[i];
vector<vector<pair<int, ll>>> adj(n);
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]);
}
return dijkstra(starts, adj);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |