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 <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
const ll INF = 1e18;
const int MAXN = 1e5 + 7;
vector<pair<int, ll>> graf[MAXN];
ll dl[MAXN][2];
class compare {
public:
bool operator() (pair<ll, int> a, pair<ll, int> b) {
return a.first > b.first;
}
};
int travel_plan(int n, int m, int R[][2], int L[], int K, int P[])
{
rep(i, MAXN) {
rep(j, 2){
dl[i][j] = INF;
}
}
rep(i, m) {
int a = R[i][0];
int b = R[i][1];
ll waga = L[i];
graf[a].push_back({b, waga});
graf[b].push_back({a, waga});
}
bool odwiedzone[n];
rep(i, n) {
odwiedzone[i] = false;
}
//dijkstra:
priority_queue<pair<ll, int>, vector<pair<ll, int>>, compare> pq;
rep(i, K) {
dl[P[i]][0] = 0;
dl[P[i]][1] = 0;
pq.push({0, P[i]});
}
while (!pq.empty()) {
pair<ll, int> p = pq.top();
pq.pop();
if (odwiedzone[p.second]) {
continue;
}
// cout << "v = " << p.second << " ile = " << p.first << '\n';
if (dl[p.second][0] < INF) {
odwiedzone[p.second] = true;
dl[p.second][1] = p.first;
for (auto syn: graf[p.second]) {
if (!odwiedzone[syn.first]) {
pq.push({syn.second + p.first, syn.first});
}
}
}
else {
dl[p.second][0] = p.first;
}
}
return dl[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... |