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>
#include <vector>
#define ff first
#define ss second
using namespace std;
double ans;
vector<pair<int,int>> v[100010];
vector<int> ar;
bitset<100001> vis;
int h;
void dfs(int a,double dist,int k){
if(vis[a]) return;
vis[a]=1;
if(a==h){
ans=min(ans,dist);
return;
}
for(pair<int,int> i:v[a]){
if(ar[i.ff]==0) dfs(i.ff,0,k);
if(ar[i.ff]==1) dfs(i.ff,dist+i.ss,k);
if(ar[i.ff]==2){
dfs(i.ff,dist+i.ss,k);
if(k>0) dfs(i.ff,dist/2+i.ss,k-1);
}
}
vis[a]=0;
}
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) {
for(int i=0;i<M;i++){
v[x[i]].push_back({y[i],c[i]});
v[y[i]].push_back({x[i],c[i]});
}
h=H;
ar=arr;
ans=1e18;
dfs(0,0,K);
for(int i=0;i<N;i++){
v[i].clear();
}
vis.reset();
if(ans==1e18) return -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... |