This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
#define ll long long
#define int long long
#define all(v) v.begin(), v.end()
#define nl '\n'
#define pb push_back
#define sz(s) (int)(s).size()
#define f first
#define s second
using namespace std;
const ll N = 1e5 + 50, MX = 1e18;
vector <pair <int, int> > g[N];
bool was[N], fr[N];
void solve(){
ll n, m;
cin >> n >> m;
ll a1, a2, b1, b2;
cin >> a1 >> a2 >> b1 >> b2;
for(int i = 1; i <= m; i++){
ll u, v, x;
cin >> u >> v >> x;
g[u].pb({v, x});
g[v].pb({u, x});
}
ll d[n + 1];
for(int i = 1; i <= n; i++){
d[i]=MX;
}
ll p[n+1];
d[a1]=0;
p[a1]=0;
priority_queue< pair<long long, int> > s;
s.push({0, a1});
while(s.size() != 0) {
int v = s.top().second;
s.pop();
if(was[v]) continue;
was[v] = 1;
for(auto [to, w]: g[v]) {
if(d[to] > d[v] + w) {
//s.erase({d[to], to});
d[to] = d[v] + w;
p[to] = v;
s.push({-d[to], to});
}
}
}
ll x = a2;
vector <pair <int, int> > v;
while(x != 0){
//cout << x << " " << p[x] << nl;
v.pb({p[x], x});
x = p[x];
}
for(auto [x, y]:v){
for(int i = 0; i < sz(g[x]); i++){
if(y == g[x][i].f){
//cout << x << " " << g[x][i].f << nl;
g[x][i].s = 0;
}
}
}
if(true) {
for (int i = 1; i <= n; i++) {
if(i == b2){
was[i]=0;
}
else {
d[i] = MX;
was[i] = 0;
}
}
d[a2] = 0;
d[b1] = 0;
s.push({0, b1});
while (s.size() != 0) {
int v = s.top().second;
s.pop();
if (was[v]) continue;
was[v] = 1;
for (auto [w, to]: g[v]) {
if (d[to] > d[v] + w) {
//s.erase({d[to], to});
d[to] = d[v] + w;
p[to] = v;
s.push({-d[to], to});
}
}
}
}
if(true) {
for (int i = 1; i <= n; i++) {
if(i == b2){
was[i]=0;
}
else {
d[i] = MX;
was[i] = 0;
}
}
d[a2] = 0;
d[a1] = 0;
s.push({0, a1});
while (s.size() != 0) {
int v = s.top().second;
s.pop();
if (was[v]) continue;
was[v] = 1;
for (auto [w, to]: g[v]) {
if (d[to] > d[v] + w) {
//s.erase({d[to], to});
d[to] = d[v] + w;
p[to] = v;
s.push({-d[to], to});
}
}
}
}
cout << d[b2] << nl;
}
signed main(){
//freopen("lca.in", "r", stdin);
//freopen("lca.out", "w", stdout);
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll ql=1;
//cin >> ql;
//tst++;
while(ql--){
solve();
}
}
# | 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... |