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 ans1,ans2,path[100010];
vector<pair<int,double>> v[100010];
vector<int> ar;
bitset<100001> vis;
priority_queue<pair<double,int>> q;
int h;
void dfs(int a){
if(vis[a]) return;
vis[a]=1;
for(pair<int,double> i:v[a]){
dfs(i.ff);
}
}
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) {
if(N==2){
if(M>0) return c[0];
else return -1;
}
if(N==3){
bool p=false,q=false;
int d;
for(int i=0;i<M;i++){
if((x[i]==0 && y[i]==H) || (x[i]==H && y[i]==0)){
p=true;
ans1=c[i];
}
else if(x[i]==0 || y[i]==0){
if(x[i]==0) d=y[i];
else d=x[i];
if(arr[d]==0) ans2=0;
else if(arr[d]==1 || (arr[d]==2 && K<1)) ans2=c[i];
else ans2=(double)c[i]/2;
for(int j=0;j<M;j++){
if((x[j]==d && y[j]==H) || (x[j]==H && y[j]==d)){
q=true;
ans2+=c[j];
}
}
}
}
if(!p && !q) return -1;
if(!p) return ans2;
if(!q) return ans1;
return min(ans1,ans2);
}
for(int i=0;i<N;i++){
path[i]=-1;
}
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]});
}
dfs(0);
q.push({0,0});
for(int i=0;i<N;i++){
if(vis[i] && !arr[i]) q.push({0,i});
}
while(!q.empty()){
double dist=q.top().ff;
int a=q.top().ss;
q.pop();
if(path[a]!=-1) continue;
path[a]=-dist;
for(pair<int,double> i:v[a]){
if(path[i.ff]==-1){
q.push({dist-i.ss,i.ff});
}
}
}
for(int i=0;i<N;i++){
v[i].clear();
}
vis.reset();
return path[H];
}
# | 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... |