이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
const double INF = numeric_limits<double>::max();
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
vector<vector<pair<int, double>>> g(N);
for (int i = 0; i < M; ++i) {
g[x[i]].emplace_back(y[i], c[i]);
g[y[i]].emplace_back(x[i], c[i]);
}
vector<vector<double>> dis(N, vector<double>(K + 1, INF));
dis[0][0] = 0;
set<tuple<double, int, int>> q;
q.emplace(dis[0][0], 0, 0);
while (!q.empty()) {
auto [w, nearest, i] = *q.begin();
q.erase(q.begin());
for (auto [to, weight]: g[nearest]) {
if (arr[to] == 0) weight = -dis[nearest][i];
if (dis[to][i] > dis[nearest][i] + weight) {
q.erase(tuple{dis[to][i], to, i});
dis[to][i] = dis[nearest][i] + weight;
q.emplace(dis[to][i], to, i);
}
if (arr[to] == 2 && i < K && dis[to][i + 1] > (dis[nearest][i] + weight) / 2.) {
q.erase(tuple{dis[to][i + 1], to, i + 1});
dis[to][i + 1] = (dis[nearest][i] + weight) / 2.;
q.emplace(dis[to][i + 1], to, i + 1);
}
}
}
double res = INF;
for (int i = 0; i <= K; ++i) res = min(dis[H][i], res);
if (res == INF) res = -1;
return res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |