#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
long long ds[100001], dt[100001], du[100001], dv[100001], l, a;
int main() {
//ifstream cin("in.in");
ios_base::sync_with_stdio(0);cin.tie(0);
int n, m, s, u, t, v, x, y;
vector<pair<int, long long>> g[100001];
priority_queue<pair<long long, int>> q;
fill(ds, ds+100001, LLONG_MAX);
fill(du, du+100001, LLONG_MAX);
fill(dt, dt+100001, LLONG_MAX);
fill(dv, dv+100001, LLONG_MAX);
cin >> n >> m;
cin >> s >> t >> u >> v;
for(int i=1;i<=m;i++){
cin >> x >> y >> l;
g[x].push_back({y, l});
g[y].push_back({x, l});
}
ds[s] = 0;
q.push({0, s});
while(!q.empty()){
x = q.top().second;
l = q.top().first;
q.pop();
for(pair<int, long long> i : g[x]){
if(ds[i.first]>(l+i.second)){
ds[i.first] = l+i.second;
q.push({ds[i.first], i.first});
}
}
}
dt[t] = 0;
q.push({0, t});
while(!q.empty()){
x = q.top().second;
l = q.top().first;
q.pop();
for(pair<int, long long> i : g[x]){
if(dt[i.first]>(l+i.second)){
dt[i.first] = l+i.second;
q.push({dt[i.first], i.first});
}
}
}
dv[v] = 0;
q.push({0, v});
while(!q.empty()){
x = q.top().second;
l = q.top().first;
q.pop();
for(pair<int, long long> i : g[x]){
if(dv[i.first]>(l+i.second)){
dv[i.first] = l+i.second;
q.push({dv[i.first], i.first});
}
}
}
a = ds[v];
l = ds[t];
for(int i=1;i<=n;i++){
if(l==ds[i]+dt[i]){
a = min(a, dv[i]);
}
}
cout << a << '\n';
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... |