#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
const double EPS = 1e-6;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
vector adj(N, vector<pair<int, int>>());
for (int i = 0; i < M; i++)
{
adj[x[i]].push_back({y[i], c[i]});
adj[y[i]].push_back({x[i], c[i]});
}
vector dp(N, vector<long double>(K + 1, 1e15));
pqg<tuple<long double, int, int>> pq;
pq.push({0, 0, 0});
for(int i = 0; i < N; i++)
if(arr[i] == 0)
pq.push({0, 0, i});
while (not pq.empty())
{
auto [cost, c, u] = pq.top();
pq.pop();
if (arr[u] == 0)
cost = 0;
if (u == H)
{
if (arr[u] == 2 and c < K)
cost /= 2;
if (dp[u][c] > cost)
dp[u][c] = cost;
continue;
}
bool con = false;
for (int i = c; i <= c; i++)
{
if (dp[u][i] <= cost or llabs(dp[u][i] - cost) <= EPS)
{
con = true;
break;
}
}
if (con)
continue;
dp[u][c] = cost;
if(c < K)
dp[u][c + 1] = min(dp[u][c], dp[u][c + 1]);
for (auto [v, w] : adj[u])
{
pq.push({cost + w, c, v});
if (arr[u] == 2 and c + 1 <= K)
pq.push({cost / 2 + w, c + 1, v});
}
}
long double mn = 1e15;
for (int i = 0; i <= K; i++)
{
if (dp[H][i] < mn and llabs(mn - dp[H][i]) > EPS)
mn = dp[H][i];
}
if (mn >= 1e15 or llabs(1e15 - mn) <= EPS)
mn = -1;
return mn;
}
# | 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... |