#include <bits/stdc++.h>
#pragma GCC oprimize("O3, unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define edge pair<ll, int>
#define c first
#define vi second
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll M = 1e18;
int n, m, s, t, u, v;
vector<edge> graf[N];
class vertex
{
private:
int v;
vector<ll> dist;
bool dw = 0;
void dijkstra()
{
if(dw)
return;
dist.assign(n, M);
priority_queue<edge, vector<edge>, greater<edge>> pq;
bool vis[n] = {};
pq.push({0, v});
dist[v] = 0;
while(!pq.empty())
{
edge t = pq.top(); pq.pop();
if(vis[t.vi])
continue;
vis[t.vi] = 1;
for(auto x: graf[t.vi])
{
if(t.c + x.c < dist[x.vi])
{
pq.push({t.c + x.c, x.vi});
dist[x.vi] = t.c + x.c;
}
}
}
}
public:
vertex(int a)
{
v = a;
}
ll distto_a(int a)
{
if(!dw)
{
dijkstra();
dw = 1;
}
return dist[a];
}
};
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> s >> t >> u >> v;
s--; t--; u--; v--;
vector<vertex> ver;
for(int i=0; i<n; i++)
{
vertex a(i);
ver.push_back(a);
}
while(m--)
{
int a, b, c; cin >> a >> b >> c;
a--; b--;
graf[a].push_back({c, b});
graf[b].push_back({c, a});
}
ll ans=M;
for(int i=0; i<n; i++)
{
if(ver[s].distto_a(i)+ver[t].distto_a(i) == ver[s].distto_a(t))
ans = min(ans, ver[v].distto_a(i));
}
cout << ans << '\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... |