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;
#define f(i,a,b) for(int i = a;i < b;i++)
#define ll long long
#define ii pair<ll,ll>
#define id pair<double,ll>
#define F first
#define S second
#define pb push_back
priority_queue<id,vector<id>,greater<id> >pq;
bool v[100005] = {0};
double dist[100005][105];
vector<vector<ii> >adj;
ll H;
void dfs(ll idx){
v[idx] = 1;
for(auto x:adj[idx]){
if(!v[x.F] && x.F != H){
dfs(x.F);
}
}
}
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) {
double ans;
H = h;
adj.assign(n+5,vector<ii>());
k = min(k,100);
f(i,0,n){
v[i] = 0;
f(j,0,k+1){
dist[i][j] = 1e18;
}
}
f(i,0,m){
adj[x[i]].pb(ii(y[i],c[i]));
adj[y[i]].pb(ii(x[i],c[i]));
}
dfs(0);
f(i,0,n){
if((arr[i] == 0 && v[i]) || i == 0){
pq.push(id(0,(k+1) * i));
dist[i][0] = 0;
}
}
ans = 1e18;
while(!pq.empty()){
id f = pq.top();
pq.pop();
double w = f.F;
ll u = f.S / (k+1);
ll ek = f.S % (k+1);
if(dist[u][ek] < w){
continue;
}
if(arr[u] == 2 && ek+1 <= k){
for(auto x:adj[u]){
if(x.F == h){
ans = min(ans,dist[u][ek]/(double)2 + (double)x.S);
}
else if(dist[x.F][ek+1] > dist[u][ek]/(double)2 + (double)x.S){
dist[x.F][ek+1] = dist[u][ek]/(double)2 + (double)x.S;
pq.push(id(dist[x.F][ek+1],(k+1) * x.F + ek+1));
}
}
}
for(auto x:adj[u]){
if(x.F == h){
ans = min(ans,dist[u][ek] + x.S);
}
else if(dist[x.F][ek] > dist[u][ek] + x.S){
dist[x.F][ek] = dist[u][ek] + x.S;
pq.push(id(dist[x.F][ek],(k+1) * x.F + ek));
}
}
}
if(ans == 1e18){
ans = -1;
}
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... |