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;
template<class A, class B> bool maximize(A& x, B y) {if (x < y) return x = y, true; else return false;}
template<class A, class B> bool minimize(A& x, B y) {if (x > y) return x = y, true; else return false;}
#define all(a) a.begin(), a.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair<db, db> pdb;
typedef pair<ld, ld> pld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
const int MAX_N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll inf = 1e18;
int n, m, s, t, x, y;
int go[MAX_N], back[MAX_N];
vector<pii> adj[MAX_N];
priority_queue<pii, vector<pii>, greater<pii>> pq;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> s >> t >> x >> y;
for (int i = 1; i <= m; i++) {
int U, V, C;
cin >> U >> V >> C;
adj[U].pb({V, C});
adj[V].pb({U, C});
}
for (int i = 1; i <= n; i++) {
go[i] = inf;
}
go[s] = 0;
pq.push({go[s], s});
while (!pq.empty()) {
int u = pq.top().se;
int currW = pq.top().fi;
pq.pop();
if (currW > go[u]) {
continue;
}
for (auto it : adj[u]) {
int v = it.fi;
int w = it.se;
if (currW + w < go[v]) {
go[v] = currW + w;
pq.push({go[v], v});
}
}
}
for (int i = 1; i <= n; i++) {
back[i] = inf;
}
back[t] = 0;
pq.push({back[t], t});
while (!pq.empty()) {
int u = pq.top().se;
int currW = pq.top().fi;
pq.pop();
if (currW > back[u]) {
continue;
}
for (auto it : adj[u]) {
int v = it.fi;
int w = it.se;
if (currW + w < back[v]) {
back[v] = currW + w;
pq.push({back[v], v});
}
}
}
for (int u = 1; u <= n; u++) {
for (auto &it : adj[u]) {
int v = it.fi;
int w = it.se;
if (go[u] + w + back[v] == go[t] || back[u] + w + go[v] == go[t]) {
it.se = 0;
}
}
}
for (int i = 1; i <= n; i++) {
go[i] = inf;
}
go[x] = 0;
pq.push({go[x], x});
while (!pq.empty()) {
int u = pq.top().se;
int currW = pq.top().fi;
pq.pop();
if (currW > go[u]) {
continue;
}
for (auto it : adj[u]) {
int v = it.fi;
int w = it.se;
if (currW + w < go[v]) {
go[v] = currW + w;
pq.push({go[v], v});
}
}
}
cout << go[y];
return 0;
}
/*
Tuesday, 24 October 2023
14:22:00
*/
# | 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... |