This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
long long const inf = 1e16;
int n, m, s, t, u, v;
vector<pair<int, long long>> g[N];
vector<int> in[N], out[N];
long long min_dist[N];
long long D[N][4];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m >> s >> t >> u >> v;
int a, b;
long long c;
for (int i = 1; i <= m; i ++) {
cin >> a >> b >> c;
g[a].push_back({b, c});
g[b].push_back({a, c});
}
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
for (int i = 1; i <= n; i ++) {
min_dist[i] = inf;
}
min_dist[s] = 0;
pq.push({0, s});
while(!pq.empty()) {
auto [d, x] = pq.top();
pq.pop();
if (min_dist[x] < d) continue;
for (pair<int, long long> e : g[x]) {
if (min_dist[e.first] > e.second + d) {
min_dist[e.first] = e.second + d;
pq.push({e.second + d, e.first});
}
}
}
priority_queue<int> pr;
pr.push(t);
while (!pr.empty()) {
int x = pr.top();
pr.pop();
for (pair<int, long long> e : g[x]) {
if (min_dist[e.first] + e.second == min_dist[x]) {
in[x].push_back(e.first);
out[e.first].push_back(x);
pr.push(e.first);
}
}
}
priority_queue<pair<pair<long long, int>, int>, vector<pair<pair<long long, int>, int>>, greater<pair<pair<long long, int>,int>>> pq2;
for (int i = 1; i <= n; i ++) {
D[i][0] = D[i][1] = D[i][2] = D[i][3] = inf;
}
D[u][0] = 0;
pq2.push({{0, u}, 0});
while (!pq2.empty()) {
auto [p, t] = pq2.top();
auto [d, x] = p;
pq2.pop();
if (D[x][t] < d) continue;
if (t == 0) {
for (auto e : g[x]) {
if (D[e.first][0] > d + e.second) {
D[e.first][0] = d + e.second;
pq2.push({{d + e.second, e.first}, 0});
}
}
for (int e : out[x]) {
if (D[e][1] > d) {
D[e][1] = d;
pq2.push({{d, e}, 1});
}
}
for (int e : in[x]) {
if (D[e][2] > d) {
D[e][2] = d;
pq2.push({{d, e}, 2});
}
}
}
if (t == 1) {
for (int e : out[x]) {
if (D[e][1] > d) {
D[e][1] = d;
pq2.push({{d, e}, 1});
}
}
for (auto e : g[x]) {
if (D[e.first][3] > d + e.second) {
D[e.first][3] = d + e.second;
pq2.push({{d + e.second, e.first}, 3});
}
}
}
if (t == 2) {
for (int e : in[x]) {
if (D[e][2] > d) {
D[e][2] = d;
pq2.push({{d, e}, 2});
}
}
for (auto e : g[x]) {
if (D[e.first][3] > d + e.second) {
D[e.first][3] = d + e.second;
pq2.push({{d + e.second, e.first}, 3});
}
}
}
if (t == 3) {
for (auto e : g[x]) {
if (D[e.first][3] > d + e.second) {
D[e.first][3] = d + e.second;
pq2.push({{d + e.second, e.first}, 3});
}
}
}
}
cout << min(min(D[v][0], D[v][1]), min(D[v][2], D[v][3]));
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | auto [d, x] = pq.top();
| ^
commuter_pass.cpp:84:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
84 | auto [p, t] = pq2.top();
| ^
commuter_pass.cpp:85:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
85 | auto [d, x] = p;
| ^
# | 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... |