이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "cyberland.h"
using namespace std;
typedef long long ll;
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>>> 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]});
}
priority_queue<pair<ll,ll>> pq;
vector<ll> d(N, 1e18), dd(N, 1e18);
{
d[H] = 0;
pq.push({0, H});
while(!pq.empty()) {
auto [x, v] = pq.top(); pq.pop();
x = -x;
if(d[v] < x) continue;
for(auto [u, w] : g[v]) {
if(d[u] > x + w) {
d[u] = x + w;
pq.push({-d[u], u});
}
}
}
}
{
dd[0] = 0;
pq.push({0, 0});
while(!pq.empty()) {
auto [x, v] = pq.top(); pq.pop();
x = -x;
if(dd[v] < x) continue;
for(auto [u, w] : g[v]) {
if(dd[u] > x + w && u != H) {
dd[u] = x + w;
pq.push({-dd[u], u});
}
}
}
}
arr[0] = 0;
double res = 1e18;
for(int i = 0; i < N; i++) if(!arr[i] && dd[i] != 1e18) res = min(res, (double)d[i]);
if(res == 1e18) res = -1;
return res;
}
// int main() {
// cin.tie(0); ios_base::sync_with_stdio(0);
// cout << fixed << setprecision(1) << solve(4, 4, 30, 3, {0, 0, 1, 2}, {1, 2, 3, 3}, {5, 4, 2, 4}, {1, 0, 2, 1}) << '\n';
// cout << fixed << setprecision(1) << solve(3, 2, 30, 2, {1, 2}, {2, 0}, {12, 4}, {1, 2, 1}) << '\n';
// }
# | 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... |