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>
using namespace std;
#define ll long long
const ll INF=1e18;
vector<vector<pair<int,int>>>v;
vector<bool>v1,v2;
void dfs(int x){
v1[x]=true;
for(auto [y,z]:v[x]){
if(!v1[y]) dfs(y);
}
}
void dfss(int x){
v2[x]=true;
for(auto [y,z]:v[x]){
if(!v2[y]) dfs(y);
}
}
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
// bool subtask=true;
// for(int i=0;i<N;i++) if(arr[i]!=1) subtask=false;
// if(subtask){
v.assign(N,vector<pair<int,int>>(0));
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]});
}
vector<bool>vis(N,0);
priority_queue<pair<ll,int>>q;
vector<ll>dp(N,INF);
v1.assign(N,0);
v2.assign(N,0);
dfs(0);
dfss(H);
dp[0]=0;
q.push({0,0});
for(int i=0;i<N;i++){
if(arr[i]==0&&v1[i]&&v2[i]){
dp[i]=0;
q.push({0,i});
}
}
while(!q.empty()){
int x=q.top().second;
q.pop();
if(vis[x]) continue;
vis[x]=true;
for(auto [z,y]:v[x]){
if(dp[x]+y<dp[z]){
dp[z]=dp[x]+y;
q.push({-dp[z],z});
}
}
}
if(dp[H]==INF) return -1.0;
return 1.0*dp[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... |