#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];
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, INT_MAX);
fill(atts, atts+n+1, INT_MAX);
fill(attt, attt+n+1, INT_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});
}
}
}
ll ans=INT_MAX;
for(int i=1; i<=n; i++){
if(atts[i]+attt[i]==atts[t]){
ans=min(ans, attv[i]);
}
}
cout << ans;
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... |