이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
using state = tuple<long double, int, int>;
const double eps = 1e-9;
double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> a) {
vector<vector<long double>> d(n, vector<long double>(k + 1, INT64_MAX));
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++) {
g[x[i]].push_back(make_pair(y[i], c[i]));
g[y[i]].push_back(make_pair(x[i], c[i]));
}
d[0][0] = 0;
priority_queue<state, vector<state>, greater<state>> pq;
pq.push({0, 0, 0});
while (!pq.empty()) {
auto [expected, who, used] = pq.top();
pq.pop();
if (d[who][used] - expected < -eps) {
continue;
}
if (who == h) {
continue;
}
for (auto [to, w] : g[who]) {
if (a[to] == 2) {
if (d[to][used] - (expected + w) > -eps) {
d[to][used] = expected + w;
pq.push({d[to][used], to, used});
}
} else if (a[to] == 1) {
if (used < k - 1 && d[to][used + 1] - ((expected + (long double) w) / 2) > -eps) {
d[to][used + 1] = (expected + (long double) w) / 2;
pq.push({d[to][used + 1], to, used + 1});
}
if (d[to][used] - (expected + w) > -eps) {
d[to][used] = expected + w;
pq.push({d[to][used], to, used});
}
} else {
if (d[to][used] > -eps) {
d[to][used] = 0;
pq.push({0, to, used});
}
}
}
}
long double cur = d[h][0];
for (int i = 0; i <= k; i++) {
if (cur - d[h][i] > -eps) {
cur = d[h][i];
}
}
return cur;
}
# | 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... |