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 "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
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 ,int>>> adj(N);
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]});
}
priority_queue<pair<double , pair<int ,int>> , vector<pair<double , pair<int ,int>>> , greater<pair<double , pair<int ,int>>>> pq;
vector<vector<double>> dist(K + 1 , vector<double>(N , 1e16));
vector<vector<bool>> vis(K + 1 , vector<bool>(N , 0));
dist[0][0] = 0;
pq.push({0 , {0 , 0}});
while(!pq.empty())
{
auto tp = pq.top();
pq.pop();
double d = tp.first ;
int node = tp.second.second , k = tp.second.first;
if(vis[k][node])
continue;
vis[k][node] = 1;
for(auto [u , cost] : adj[node])
{
double nd = d + cost;
if(arr[u] == 0)
{
nd = 0;
}
if(nd < dist[k][u])
{
dist[k][u] = nd;
pq.push({nd , {k , u}});
}
if(arr[u] == 2 && k >= 1)
{
nd/=2.0;
if(nd < dist[k][u])
{
dist[k - 1][u] = nd;
pq.push({nd , {k - 1 , u}});
}
}
}
}
double mn = 1e16;
for(int i = 0 ; i <= K ; i++)
{
mn= min(mn , dist[i][H]);
}
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... |