이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define pid pair<int,double>
#define f first
#define s second
#define A pair<double, pair<int,int>>
vector<pid> adj[100005];
bool reach[100005];
void dfs(int u) {
reach[u] = 1;
for(auto [v, w]:adj[u]) {
if(!reach[v]) dfs(v);
}
}
double mindis[100005][35];
double solve(int N, int M, int K, int H, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) {
for(int i=0;i<N;i++) {
adj[i].clear();
reach[i] = 0;
for(int j=0;j<=K;j++) {
mindis[i][j] = 1e18;
}
}
for(int i=0;i<M;i++) {
adj[x[i]].push_back({y[i], (double)c[i]});
adj[y[i]].push_back({x[i], (double)c[i]});
}
dfs(0);
if(!reach[H]) return -1;
priority_queue<A, vector<A>, greater<A>> pq;
pq.push({0, {0, 0}});
mindis[0][0] = 0;
for(int i=1;i<N;i++) {
if(reach[i] && arr[i]==0) {
pq.push({0, {i, 0}});
mindis[i][0] = 0;
}
}
while(!pq.empty()) {
double dis = pq.top().f;
auto [u, ct] = pq.top().s;
pq.pop();
if(mindis[u][ct]!=dis || u==H) continue;
for(auto [v, w]:adj[u]) {
if(arr[v]==1 && mindis[v][ct]>dis+w) {
mindis[v][ct] = dis+w;
pq.push({mindis[v][ct], {v, ct}});
} else if(arr[v]==2 && ct<K && mindis[v][ct+1]>(dis+w)/2) {
mindis[v][ct+1] = (dis+w)/2;
pq.push({mindis[v][ct+1], {v, ct+1}});
}
}
}
double ret = 1e18;
for(int i=0;i<=K;i++) ret = min(ret, mindis[H][i]);
return ret;
}
# | 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... |