This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// author: phucthuhigh
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define cint(x) int(x - '0')
#define cchar(x) char(x + '0')
#define pb push_back
#define fi first
#define se second
#define pii pair<ll, int>
#define llll pair<long long, long long>
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) x/__gcd(x, y)*y
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef long double ldb;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const long long INFLL = (long long)1e18 + 7;
const int maxn = 1e5 + 5;
vector<pii> a[maxn];
ll d[4][maxn], n, m;
void dijkstra(int id, int s) {
for (int i = 1; i <= n; i++) d[id][i] = INFLL;
priority_queue<pii, vector<pii>, greater<pii> > q;
d[id][s] = 0;
q.push({d[id][s], s});
while (sz(q)) {
ll dist; int u; tie(dist, u) = q.top(); q.pop();
if (dist != d[id][u]) continue;
for (auto [w, v]: a[u]) {
if (d[id][v] > w + dist) q.push({d[id][v] = w + dist, v});
}
}
}
void solve() {
cin >> n >> m;
ll s, t, u, v; cin >> s >> t >> u >> v;
for (int i = 1; i <= m; i++) {
int x, y; ll w; cin >> x >> y >> w;
a[x].pb({w, y});
a[y].pb({w, x});
}
dijkstra(0, s);
dijkstra(1, t);
dijkstra(2, u);
dijkstra(3, v);
cout << min(d[2][v], d[1][v]);
}
int main() {
fastIO
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
int t = 1;
while (t--) solve();
cerr << "Times: " << TIME << "s." << endl;
return 0;
}
/**
* {\__/}
* (• .•)
* / >♥️
**/
# | 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... |