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;
typedef long long int ll;
const int MAXN = 2e5 + 10;
int n, m, s, t, x, y, parid[MAXN], par[MAXN], uu[MAXN], vv[MAXN];
ll w[MAXN], d[MAXN], d2[MAXN], d3[MAXN], d0[MAXN], d1[MAXN], dpx[MAXN], dpy[MAXN], ans = LLONG_MAX;
vector <pair<int,int>> adj[MAXN];
bool mark[MAXN];
inline void dij(int r){
for(int i = 0; i < n; i++) d[i] = LLONG_MAX / 2ll;
d[r] = 0;
set <pair<ll, int>> st;
st.insert({0ll, r});
while(!st.empty()){
int v = st.begin()->second;
st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ind = i.second;
if(d[u] > d[v] + w[ind]){
st.erase({d[u], u});
d[u] = d[v] + w[ind];
st.insert({d[u], u});
par[u] = v; parid[u] = ind;
}
}
}
return;
}
inline void dij2(int r){
for(int i = 0; i < n; i++) d2[i] = LLONG_MAX / 2ll;
d2[r] = 0;
set <pair<ll, int>> st;
st.insert({0ll, r});
while(!st.empty()){
int v = st.begin()->second;
st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ind = i.second;
if(d2[u] > d2[v] + w[ind]){
st.erase({d2[u], u});
d2[u] = d2[v] + w[ind];
st.insert({d2[u], u});
par[u] = v; parid[u] = ind;
}
}
}
return;
}
inline void dij3(int r){
for(int i = 0; i < n; i++) d3[i] = LLONG_MAX / 2ll;
d3[r] = 0;
set <pair<ll, int>> st;
st.insert({0ll, r});
while(!st.empty()){
int v = st.begin()->second;
st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ind = i.second;
if(d3[u] > d3[v] + w[ind]){
st.erase({d3[u], u});
d3[u] = d3[v] + w[ind];
st.insert({d3[u], u});
par[u] = v; parid[u] = ind;
}
}
}
return;
}
inline void dij0(int r){
for(int i = 0; i < n; i++) d0[i] = LLONG_MAX / 2ll;
d0[r] = 0;
set <pair<ll, int>> st;
st.insert({0ll, r}); dpx[r] = d2[r]; dpy[r] = d3[r];
while(!st.empty()){
int v = st.begin()->second;
st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ind = i.second;
if(d0[u] > d0[v] + w[ind]){ //if((w[i] + d[u] + d2[v] <= d[t]) || (w[i] + d2[u] + d[v] <= d[t]))
st.erase({d0[u], u});
d0[u] = d0[v] + w[ind];
st.insert({d0[u], u});
par[u] = v; parid[u] = ind;
if(d[t] >= d[u] + d1[u]){
dpx[u] = min(d2[u], dpx[v]); dpy[u] = min(d3[u], dpy[v]);
ans = min(dpx[u] + d3[u], ans); ans = min(dpy[u] + d2[u], ans);
}
}
}
}
return;
}
inline void dij1(int r){
for(int i = 0; i < n; i++) d1[i] = LLONG_MAX / 2ll;
d1[r] = 0;
set <pair<ll, int>> st;
st.insert({0ll, r});
while(!st.empty()){
int v = st.begin()->second;
st.erase(*st.begin());
for(auto i: adj[v]){
int u = i.first, ind = i.second;
if(d1[u] > d1[v] + w[ind]){
st.erase({d1[u], u});
d1[u] = d1[v] + w[ind];
st.insert({d1[u], u});
par[u] = v; parid[u] = ind;
}
}
}
return;
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m >> s >> t >> x >> y; s--; t--; x--; y--;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v >> w[i];
u--; v--; uu[i] = u; vv[i] = v;
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
dij2(x); dij3(y); ans = d2[y];
dij(s); dij1(t); dij0(s);
cout << ans << 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... |