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>
using namespace std;
#define F first
#define S second
using ll = long long;
const int INF = 1e9 + 7;
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr)
{
vector<vector<pair<int, double>>> adj(N);
for (int i = 0; i < M; i++)
{
adj[x[i]].emplace_back(y[i], double(c[i]));
adj[y[i]].emplace_back(x[i], double(c[i]));
}
queue<int> Q;
vector<bool> vis(N);
Q.push(0);
vis[0] = 1;
while (!Q.empty())
{
int u = Q.front();
Q.pop();
if (u == H)
continue;
for (auto i : adj[u])
if (!vis[i.F])
{
vis[i.F] = 1;
Q.push(i.F);
}
}
priority_queue<pair<double, int>> PQ;
vector<double> dist(N, 1e16);
for (int i = 1; i < N; i++)
if (arr[i] == 0 && vis[i])
{
dist[i] = 0;
PQ.emplace(0, i);
}
dist[0] = 0;
PQ.emplace(0, 0);
while (!PQ.empty())
{
double d; int u;
tie(d, u) = PQ.top();
PQ.pop();
if (d != dist[u])
continue;
for (auto i : adj[u])
{
int v; double w;
tie(v, w) = i;
if (dist[v] > dist[u] + w)
PQ.emplace(dist[v] = dist[u] + w, v);
}
}
for (int i = 0; i < N; i++)
{
if (arr[i] == 2 && vis[i])
{
dist[i] /= 2.0;
double mn = 1e16;
for (auto j : adj[i])
if (j.F != H)
mn = min(mn, j.S);
if (mn < dist[i])
for (int j = 0; j < K - 1; j++)
dist[i] = (dist[i] + mn) / 2.0;
PQ.emplace(dist[i], i);
}
else if (arr[i] == 0 && vis[i])
PQ.emplace(0, i);
else
dist[i] = 1e16;
}
dist[0] = 0.0;
PQ.emplace(0, 0);
while (!PQ.empty())
{
int u; double d;
tie(d, u) = PQ.top();
PQ.pop();
if (d != dist[u])
continue;
for (auto i : adj[u])
{
int v; double w;
tie(v, w) = i;
if (dist[v] > dist[u] + w)
PQ.emplace(dist[v] = dist[u] + w, v);
}
}
return (dist[H] == 1e16 ? -1.0 : dist[H]);
}
# | 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... |