이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include<bits/stdc++.h>
using namespace std;
#define vec vector
#define int long long
#define float double
const int INF = 1e17;
double solve(int32_t N, int32_t M, int32_t K, int32_t H, std::vector<int32_t> x, std::vector<int32_t> y, std::vector<int32_t> c, std::vector<int32_t> t) {
float ans = INF;
int n = N;
int m = M;
int k = K;
priority_queue<pair<pair<int, float>, int>, vector<pair<pair<int, float>, int>>, greater<pair<pair<int, float>, int>>> pq;
vec<vec<bool>> vis(k+1, vec<bool>(n, false));
vec<vec<pair<int, int>>> g(n);
for(int i = 0; i<m; i++) {
g[x[i]].push_back({y[i], c[i]});
g[y[i]].push_back({x[i], c[i]});
}
pq.push({{0, 0}, 0});
vec<bool> dfs_vis(n, false);
vec<int> stk{0};
dfs_vis[0] = true;
while(stk.size() > 0) {
int u = stk.back();
stk.pop_back();
if(u==H) continue;
if(t[u] == 0) {
pq.push({{0, 0}, u});
}
for(auto e : g[u]) {
if(dfs_vis[e.first]) continue;
stk.push_back(e.first);
dfs_vis[e.first] = true;
}
}
while(pq.size() > 0) {
pair<pair<int, float>, int> cur = pq.top();
pq.pop();
int ck = cur.first.first;
float d = cur.first.second;
int u = cur.second;
if(ck > k) break;
if(u == H) {
ans = min(ans, d);
continue;
}
if(vis[ck][u]) {
continue;
}
vis[ck][u] = true;
for(auto e : g[u]) {
int v = e.first;
float w = e.second;
if(vis[ck][v]) continue;
pq.push({{ck, d+w}, v});
}
if(t[u] == 2) {
pq.push({{ck+1, d/2}, u});
}
}
if(ans == INF) return -1;
return ans;
}
# | 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... |