이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author : Lăng Trọng Đạt
* created: 2023-08-26
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
const int MAXN = 1e5 + 5;
const int INF = 1e18;
vector<pii> adj[MAXN];
int far[MAXN];
int n, m, x, y, s, t;
int a, b, w;
int res = INF;
set<pii> bought;
void truy_vet() {
int endd = t, start = far[t]; // both endpoint of railway
while (start) {
bought.insert({start, endd});
bought.insert({endd, start});
endd = start;
start = far[start];
}
}
int dijkstra(int start, int target, bool truy) {
priority_queue<pii, vector<pii>, greater<pii>> pq;
vector<int> d(n + 1, INF); // minimum distance from start to node i
pq.push({0, start});
d[start] = 0;
while (pq.size()) {
auto[dist, v] = pq.top(); pq.pop();
// db(dist, v, d[v])
if (dist != d[v]) continue;
if (v == target) {
// db(res, dist, target, pq.size())
if (!truy) return dist;
truy_vet();
res = min(res, dijkstra(x, y, 0));
bought.clear();
continue;
}
for (auto[u, w] : adj[v]) {
// db(u, v, w, dist, truy)
if (bought.count({u, v})) w = 0;
if (d[u] > w + dist or (truy && d[u] == w + dist)) {
d[u] = w + dist;
pq.push({d[u], u});
if (truy) far[u] = v;
}
}
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> s >> t >> x >> y;
db(n, m)
while (m--) {
cin >> a >> b >> w;
adj[a].pb({b, w});
adj[b].pb({a, w});
}
dijkstra(s, t, true);
cout << res;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int64_t dijkstra(int64_t, int64_t, bool)':
commuter_pass.cpp:43:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
43 | auto[dist, v] = pq.top(); pq.pop();
| ^
commuter_pass.cpp:54:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | for (auto[u, w] : adj[v]) {
| ^
commuter_pass.cpp:38:52: warning: control reaches end of non-void function [-Wreturn-type]
38 | priority_queue<pii, vector<pii>, greater<pii>> pq;
| ^~
# | 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... |