이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define flt long double
struct edge {
int to;
long long cost;
};
const flt inf = 1e100;
int n, m;
vector<vector<edge>> g;
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) {
n = N;
m = M;
K = min(K, 100);
g.assign(n, {});
for (int i = 0; i < m; i += 1) {
int u = x[i];
int v = y[i];
int cost = c[i];
g[u].push_back({v, cost});
g[v].push_back({u, cost});
}
vector<flt> dst(n, inf);
dst[0] = 0;
for(int iter = 0; iter <= K + 2; iter += 1){
set<pair<flt, int>> q;
for(int i = 0; i < n; i += 1){
q.emplace(dst[i], i);
}
while(!q.empty()){
int v = q.begin()->second;
q.erase(q.begin());
if(v == H){
continue;
}
for(auto [to, cost]: g[v]){
if(dst[to] > dst[v] + cost){
q.erase(make_pair(dst[to], to));
dst[to] = dst[v] + cost;
q.insert(make_pair(dst[to], to));
}
}
}
auto new_dst = dst;
for(int i = 0; i < n; i += 1){
if(dst[i] < inf / 10){
if(arr[i] == 0){
new_dst[i] = 0;
} else if(arr[i] == 2 && iter > 1 && iter != K + 2){
for(auto [to, cost]: g[i]){
new_dst[to] = min(new_dst[to], dst[i] / 2 + (flt)(cost));
}
}
}
}
dst = new_dst;
}
if(dst[H] >= inf / 10){
return -1;
}
return dst[H];
}
/*
3 2 30 2
*/
# | 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... |