#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define pii pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
ll n, m, s, t, u, v, a, b, c;
ll attv[100005], atts[100005], attt[100005], attu[100005];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m >> s >> t >> u >> v;
vector<pii>graph[100005];
for(int i=0; i<m; i++){
cin >> a >> b >> c;
graph[a].pb({c, b});
graph[b].pb({c, a});
}
fill(attv, attv+n+1, LLONG_MAX);
fill(atts, atts+n+1, LLONG_MAX);
fill(attt, attt+n+1, LLONG_MAX);
fill(attu, attu+n+1, LLONG_MAX);
priority_queue<pii, vector<pii>, greater<pii>>pq;
attv[v]=0;
pq.push({0, v});
while(!pq.empty()){
a=pq.top().se;
b=pq.top().fi;
pq.pop();
if(b!=attv[a])
continue;
for(auto p : graph[a]){
if(attv[p.se]>attv[a]+p.fi){
attv[p.se]=attv[a]+p.fi;
pq.push({attv[p.se], p.se});
}
}
}
atts[s]=0;
pq.push({0, s});
while(!pq.empty()){
a=pq.top().se;
b=pq.top().fi;
pq.pop();
if(b!=atts[a])
continue;
for(auto p : graph[a]){
if(atts[p.se]>atts[a]+p.fi){
atts[p.se]=atts[a]+p.fi;
pq.push({atts[p.se], p.se});
}
}
}
attt[t]=0;
pq.push({0, t});
while(!pq.empty()){
a=pq.top().se;
b=pq.top().fi;
pq.pop();
if(b!=attt[a])
continue;
for(auto p : graph[a]){
if(attt[p.se]>attt[a]+p.fi){
attt[p.se]=attt[a]+p.fi;
pq.push({attt[p.se], p.se});
}
}
}
attu[u]=0;
pq.push({0, u});
while(!pq.empty()){
a=pq.top().se;
b=pq.top().fi;
pq.pop();
if(b!=attu[a])
continue;
for(auto p : graph[a]){
if(attu[p.se]>attu[a]+p.fi){
attu[p.se]=attu[a]+p.fi;
pq.push({attu[p.se], p.se});
}
}
}
ll mn1=LLONG_MAX, mn2=LLONG_MAX;
for(int i=1; i<=n; i++){
if(atts[i]+attt[i]==atts[t]){
mn1=min(mn1, attv[i]);
mn2=min(mn2, attv[i]);
}
}
cout << min(mn1+mn2, attu[v]);
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... |