이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
using namespace std;
#define db double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0)\
#define pdi pair<db, int>
const int sz = 1e5;
const db inf = 1e14;
const db eps = 1e-7;
int n, m, k, h;
db d[sz][70];
vector<pair<int, double>> g[sz];
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 = K, h = H;
k = min(69, k);
for(int i = 1; i <= n; i++){
for(int j = 0; j <= k; j++){
d[i][j] = inf;
}
}
for(int i = 0; i < m; i++){
g[x[i] + 1].push_back({y[i] + 1, c[i]});
g[y[i] + 1].push_back({x[i] + 1, c[i]});
}
priority_queue<pair<pdi, int>, vector<pair<pdi, int>>, greater<pair<pdi, int>>> pq;
d[1][0] = 0;
pq.push({{0.0, 0}, 1});
for(int i = 2; i <= n; i++){
if(arr[i - 1] == 0) d[i][0] = 0, pq.push({{0.0, 0}, i});
}
while(!pq.empty()){
int cur = pq.top().second, cr = pq.top().first.second;
if(d[cur][cr] - pq.top().first.first < -eps){
pq.pop();
continue;
}
pq.pop();
for(auto i : g[cur]){
if(d[i.first][cr] - d[cur][cr] - i.second > eps){
d[i.first][cr] = d[cur][cr] + i.second;
pq.push({{d[i.first][cr], cr}, i.first});
}
if(arr[cur - 1] == 2){
if(d[i.first][cr + 1] - (d[cur][cr] + i.second) / 2.0 > eps){
d[i.first][cr + 1] = (d[cur][cr] + i.second) / 2.0;
pq.push({{d[i.first][cr + 1], cr + 1}, i.first});
}
}
}
}
// for(int i = 1; i <= n; i++){
// for(int j = 0; j <= k; j++){
// cout << d[i][j] << " ";
// }
// cout << endl;
// }
db res = inf;
for(int i = 0; i <= k; i++){
// cout << d[H + 1][i] << " ";
res = min(res, d[H + 1][i]);
}
return (res == inf ? -1 : res);
}
# | 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... |