# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
990671 | Ibrohim0704 | Cyberland (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
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 <vector>
#include <queue>
#include <algorithm>
using namespace std;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
vector<double> min_time(N, numeric_limits<double>::infinity());
min_time[0] = 0;
auto cmp = [](const pair<double, int>& a, const pair<double, int>& b) {
return a.first > b.first;
};
priority_queue<pair<double, int>, vector<pair<double, int>>, decltype(cmp)> pq(cmp);
pq.push({0, 0});
while (!pq.empty()) {
double time = pq.top().first;
long long int country = pq.top().second;
pq.pop();
if (country == H) {
return time;
}
for (long long int i = 0; i < M; ++i) {
long long int neighbor;
if (x[i] == country) {
neighbor = y[i];
} else if (y[i] == country) {
neighbor = x[i];
} else {
continue;
}
long long double neighbor_time = time + c[i];
if (arr[neighbor] == 2 && K > 0) {
neighbor_time /= 2;
--K;
}
if (neighbor_time < min_time[neighbor]) {
min_time[neighbor] = neighbor_time;
pq.push({neighbor_time, neighbor});
}
}
}
return -1;
}