이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "cyberland.h"
#include <bits/stdc++.h>
template <typename T>
using PQG = std::priority_queue<T, std::vector<T>, std::greater<T>>;
#ifdef LOCAL
#include "template\debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
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) {
std::vector<std::vector<std::pair<int, int>>> adj(N);
for (int i = 0; i < M; i++) {
int u = x[i], v = y[i], w = c[i];
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
PQG<std::pair<double, int>> pq;
double ans = 1e18;
std::vector<double> dp(N, 1e18);
pq.emplace(0, 0);
dp[0] = 0;
while (pq.size()) {
auto [d, u] = pq.top();
pq.pop();
dbg(d, u);
if (u == H) continue;
if (d > dp[u]) continue;
for (auto [v, w] : adj[u]) {
auto nd = d + w;
if (nd < dp[v]) {
dp[v] = nd;
pq.emplace(nd, v);
}
}
}
dbg(dp);
ans = dp[H];
return (ans < 1e18 ? ans : -1);
}
#ifdef LOCAL
#include <cassert>
#include <cstdio>
#include <vector>
int main() {
int T;
assert(1 == scanf("%d", &T));
while (T--){
int N,M,K,H;
assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
std::vector<int> x(M);
std::vector<int> y(M);
std::vector<int> c(M);
std::vector<int> arr(N);
for (int i=0;i<N;i++)
assert(1 == scanf("%d", &arr[i]));
for (int i=0;i<M;i++)
assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
}
}
#endif
# | 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... |