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>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define ld long double
#define pii pair<int,int>
#define fs first
#define sc second
#define mt make_tuple
const ld inf = 1e15;
const int mxn = 2e5+10;
const int lim = 70;
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++){
dist[i+N] = inf;
done[i] = done[i+N] = false;
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;
int pid = (now<N?now:now-N);
for(auto &[nxt,w]:paths[pid]){
if(!able[nxt]||done[nxt+N])continue;
if(dist[nxt+N] > dist[now]+w){
dist[nxt+N] = dist[now]+w;
if(nxt != ban)pq.push(make_pair(dist[nxt+N],nxt+N));
}
}
}
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*2;i++)able[i] = true;
for(int i = 0;i<N;i++)dist[i] = inf;
dist[0] = 0;
DIJKSTRA::GO(H);
for(int i = 0;i<N;i++){
able[i] = able[i+N] = (min(dist[i],dist[i+N])+1<inf);
}
for(int i = 0;i<N;i++){
if(able[i]&&arr[i] == 0)dist[i] = 0;
else dist[i] = inf;
}
if(!able[H])return -1;
dist[0] = 0;
ld ans = inf;
for(int i = 0;i<=min(K,lim);i++){
DIJKSTRA::GO(H);
ans = min({ans,dist[H],dist[H+N]});
if(i+1<=min(K,lim)&&arr[H] == 2)ans = min({ans,dist[H+N]/2});
for(int j = 0;j<N;j++){
dist[j] = min(dist[j],dist[j+N]);
if(able[j]&&arr[j] == 2)dist[j] = min(dist[j],dist[j+N]/2);
}
dist[H] = inf;
}
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... |