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 <vector>
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define pii pair<int,int>
#define fs first
#define sc second
const ld inf = 1e15;
const int mxn = 1e5+10;
const int lim = 60;
ld dist[mxn];
vector<pii> paths[mxn];
bitset<mxn> able;
int N,M;
namespace DIJKSTRA{
bitset<mxn> done;
priority_queue<pair<ld,int>,vector<pair<ld,int>>,greater<pair<ld,int>>> pq;
void GO(int ban){
for(int i = 0;i<N;i++){
done[i] = 0;
if(ban != i&&able[i])pq.push(make_pair(dist[i],i));
}
while(!pq.empty()){
auto now = pq.top().sc;
pq.pop();
if(done[now])continue;
done[now] = true;
for(auto &[nxt,w]:paths[now]){
if(!able[nxt]||done[nxt])continue;
if(dist[nxt]>dist[now]+w){
dist[nxt] = dist[now]+w;
if(nxt != ban)pq.push(make_pair(dist[nxt],nxt));
}
}
}
return;
}
}
void init(){
for(int i = 0;i<N;i++)paths[i].clear();
}
double solve(int NN, int MM, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> z, std::vector<int> arr) {
init();
N = NN,M = MM;
for(int i = 0;i<M;i++){
int a = x[i],b = y[i],c = z[i];
paths[a].push_back(pii(b,c));
paths[b].push_back(pii(a,c));
}
for(int i = 0;i<N;i++)able[i] = true,dist[i] = inf;
dist[0] = 0;
DIJKSTRA::GO(H);
for(int i = 0;i<N;i++){
if(dist[i]+1<inf)able[i] = true;
else able[i] = false;
}
if(!able[H])return -1;
for(int i = 0;i<N;i++){
if(able[i]&&arr[i] == 0)dist[i] = 0;
else dist[i] = inf;
}
dist[0] = 0;
ld ans = inf;
for(int i = 0;i<=min(lim,K);i++){
DIJKSTRA::GO(-1);
ans = min(ans,dist[H]);
if(arr[H] == 2&&i+1<=min(lim,K))ans = min(ans,dist[H]/2);
dist[H] = inf;
for(int j = 0;j<N;j++){
if(!able[j])dist[j] = inf;
else if(arr[j] == 2)dist[j] /= 2;
else if(arr[j] == 0)dist[j] = 0;
}
}
return 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... |