This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int32_t> powers;
vector<vector<pair<int,long double>>> adj;
priority_queue<pair<int,pair<long double,int>>,vector<pair<int,pair<long double,int>>>,greater<>> q;
vector<bool> visited;
void dfs(int x){
if(visited[x])return;
visited[x]=true;
if(powers[x]==0)q.emplace(0, make_pair(0,x));
for(auto[dest,c]:adj[x])dfs(dest);
}
double solve(int32_t N, int32_t M, int32_t K, int32_t H, vector<int32_t> x, vector<int32_t> y, vector<int32_t> c, vector<int32_t> arr) {
K = min(K, 67);
swap(powers,arr);
visited = vector<bool>(N);
adj = vector<vector<pair<int,long double>>>(N);
while(!q.empty())q.pop();
powers[0] = 0;
visited[H]=true;
for(int i=0;i<M;i++){
adj[x[i]].emplace_back(y[i],c[i]);
adj[y[i]].emplace_back(x[i],c[i]);
}
long double ans = 4e15;
dfs(0);
vector<vector<bool>> vis(N,vector<bool>(K+1));
while(!q.empty()){
auto [uses,curr] = q.top();q.pop();
auto [tim,idx] = curr;
if(idx==H){
ans = min(ans,tim);
continue;
}
if(vis[idx][uses])continue;
vis[idx][uses]=true;
for(auto[dest,cost]:adj[idx]){
if(!vis[dest][uses])q.emplace(uses,make_pair(tim+cost,dest));
if(powers[dest]==2 and uses<K and !vis[dest][uses+1])q.emplace(uses+1,make_pair((tim+cost)/(long double)(2),dest));
}
}
return ans>=4e15 ? -1 : ans;
}
# | 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... |