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 <iostream>
#include <queue>
using namespace std;
vector<int> vals;
vector<vector<pair<int,int>>> adjlist;
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[])
{
vals.resize(n, -1);
adjlist.resize(n);
for (int i = 0; i < m; i++)
{
adjlist[R[i][0]].push_back({R[i][1], L[i]});
adjlist[R[i][1]].push_back({R[i][0], L[i]});
}
priority_queue<pair<int,int>> pq;
for (int i = 0; i < k; i++)
{
vals[P[i]] = -2;
pq.push({0, P[i]});
}
while (!pq.empty())
{
int curr = pq.top().second;
int val = -pq.top().first;
pq.pop();
if (vals[curr] == -1)
{
vals[curr] = -2;
continue;
}
if (vals[curr] > -1) continue;
vals[curr] = val;
for (auto p : adjlist[curr])
{
if (vals[p.first] > -1) continue;
pq.push({-vals[curr] - p.second, p.first});
}
}
return vals[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... |