이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
struct node {
int v;
long long time;
int prev;
bool operator<(const node &rhs) const {
return time > rhs.time;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int N, M, S, T, U, V;
cin >> N >> M >> S >> T >> U >> V;
vector<pair<int, long long>> adj[N + 1];
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
auto distcalc = [&](int s) {
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
vector<long long> dist(N + 1, 1e18);
vector<bool> vis(N + 1);
q.push({0, s});
while (!q.empty()) {
pair<long long, int> v = q.top();
q.pop();
if (vis[v.second]) continue;
vis[v.second] = true;
dist[v.second] = v.first;
for (auto u : adj[v.second]) {
q.push({u.second + v.first, u.first});
}
}
return dist;
};
vector<long long> fu = distcalc(U), fv = distcalc(V);
priority_queue<node> q;
vector<bool> vis(N + 1);
vector<long long> mtu(N + 1, 1e18), mtv(N + 1, 1e18);
q.push({S, 0, S});
long long bt = -1, ans = 1e18;
while (!q.empty()) {
node v = q.top();
q.pop();
if (vis[v.v]) {
if (min(mtu[v.prev], fu[v.v]) + min(mtv[v.prev], fv[v.v]) < mtu[v.v] + mtv[v.v]) {
mtu[v.v] = min(fu[v.v], mtu[v.prev]);
mtv[v.v] = min(fv[v.v], mtv[v.prev]);
}
continue;
}
vis[v.v] = true;
mtu[v.v] = min(fu[v.v], mtu[v.prev]);
mtv[v.v] = min(fv[v.v], mtv[v.prev]);
for (auto u : adj[v.v]) {
q.push({u.first, v.time + u.second, v.v});
}
}
cout << min(mtu[T] + mtv[T], fu[V]) << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:59:15: warning: unused variable 'bt' [-Wunused-variable]
59 | long long bt = -1, ans = 1e18;
| ^~
commuter_pass.cpp:59:24: warning: unused variable 'ans' [-Wunused-variable]
59 | long long bt = -1, ans = 1e18;
| ^~~
# | 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... |