이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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.resize(N);
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... |