#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target ("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
const int N = 100005;
vector<pair<int, long long>> graph[N];
long long dv[N], dt[N], ds[N];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, s, t, u, v; cin >> n >> m >> s >> t >> u >> v;
for(int i = 0; i < m; i++)
{
int a, b;
long long c;
cin >> a >> b >> c;
graph[a].push_back({b, c});
graph[b].push_back({a, c});
}
priority_queue <pair<long long, int>> pq;
for(int i = 0; i <= n; i++)ds[i]= 1e18;
ds[s]=0;
pq.push({0, s});
while(pq.size())
{
pair<long long,int> x = pq.top();
pq.pop();
for(auto i: graph[x.second])
{
if(ds[i.first] > x.first+i.second)
{
pq.push({x.first+i.second, i.first});
ds[i.first]=x.first+i.second;
}
}
}
for(int i = 0; i <= n; i++)dt[i]= 1e18;
dt[t]=0;
pq.push({0, t});
while(pq.size())
{
pair<long long,int> x = pq.top();
pq.pop();
for(auto i: graph[x.second])
{
if(dt[i.first] > x.first+i.second)
{
pq.push({x.first+i.second, i.first});
dt[i.first]=x.first+i.second;
}
}
}
for(int i = 0; i <= n; i++)dv[i]= 1e18;
dv[v]=0;
pq.push({0, v});
while(pq.size())
{
pair<long long,int> x = pq.top();
pq.pop();
for(auto i: graph[x.second])
{
if(dv[i.first] > x.first+i.second)
{
pq.push({x.first+i.second, i.first});
dv[i.first]=x.first+i.second;
}
}
}
/*
int du[100005]={0};
du[u]=0;
priv = u;
pq.push({0, u});
while(pq.size())
{
pair<int,int> x = pq.top();
pq.pop();
for(auto i: graph[x.second])
{
if(i.first==priv)continue;
if(du[i.first]==0 || du[i.first] > x.first+i.second)
{
pq.push({x.first+i.second, i.first});
du[i.first]=x.first+i.second;
}
}
priv=x.second;
}
*/
long long rezv= 1e18;
for(int i = 1; i <= n; i++)
{
if(dv[i] < rezv)
{
if(dt[i]+ds[i]==ds[t])
{
rezv=dv[i];
}
}
}
cout << rezv << "\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... |