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;
using ll = long long;
int n, m, s, t, u, v, a, b, c, x;
vector<bool> vis;
vector<ll> dis, diss, dist, disu, disv;
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m >> s >> t >> u >> v;
vector<pair<int, int>> E[n + 1];
while (m--) {
cin >> a >> b >> c;
E[a].push_back({b, c});
E[b].push_back({a, c});
}
auto f = [&](int st) -> vector<ll>{
dis.assign(n + 1, LLONG_MAX); dis[st] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q;
q.push({0, st});
while (!q.empty()) {
x = q.top().second; q.pop();
for (auto i : E[x]) {
if (dis[x] + i.second < dis[i.first]) {
dis[i.first] = dis[x] + i.second;
q.push({dis[i.first], i.first});
}
}
}
return dis;
};
diss = f(s); dist = f(t);
disu = f(u); disv = f(v);
ll ans = disu[v];
vis.assign(n + 1, false);
priority_queue<vector<ll>> q;
q.push({0, -(disu[s] + disv[s]), s, disu[s], disv[s]});
while (!q.empty()) {
vector<ll> v = q.top(); q.pop();
// for(ll x : v) cout<<x<<' ';
// cout<<'\n';
if (v[2] == t) {
ans = min(ans, -v[1]);
continue;
}
if (vis[v[2]]) continue;
vis[v[2]] = true;
for (auto i : E[v[2]]) {
if (diss[v[2]] + i.second == diss[i.first] && diss[i.first] + dist[i.first] == diss[t]) {
ll a = min(v[3], disu[i.first]), b = min(v[4], disv[i.first]);
q.push({-diss[i.first], -(a + b), i.first, a, b});
}
}
}
cout << ans;
}
# | 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... |