이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
const double INF = 1e18;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
struct Data{
int u, k;
double w;
Data(int _u, int _k, double _w) : u(_u), k(_k), w(_w) {}
friend bool operator <(Data a, Data b){
return a.w > b.w;
}
};
double solve(int n, int m, int k, int h, vector<int>x, vector<int>y, vector<int>c, vector<int>arr) {
vector<vector<pair<int, int>>>e(n);
for(int i = 0; i < m; i++){
e[x[i]].emplace_back(y[i], c[i]);
e[y[i]].emplace_back(x[i], c[i]);
}
minimize(k, 70);
priority_queue<Data>q;
vector<vector<double>>d(n, vector<double>(k + 1, INF));
q.emplace(0, k, d[0][k] = 0.0);
while(!q.empty()){
auto [u, remain, w] = q.top();
q.pop();
if(w > d[u][remain] || u == h){
continue;
}
for(auto& [v, weight] : e[u]){
if(arr[v] == 0){
if(d[v][remain] > 0.0){
q.emplace(v, remain, d[v][remain] = 0.0);
}
}
else{
double W = w + double(weight);
if(W < d[v][remain]){
q.emplace(v, remain, d[v][remain] = W);
}
if(arr[v] == 2 && remain > 0 && (W /= 2.0) < d[v][remain - 1]){
q.emplace(v, remain - 1, d[v][remain - 1] = W);
}
}
}
}
double ans = INF;
for(int i = 0; i <= k; i++){
minimize(ans, d[h][i]);
}
return ans < INF ? ans : -1;
}
# | 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... |