#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 1e18;
vector<pair<int, int>> adj[MAXN];
map<pair<int, int>, int> marc_edge;
int marc[MAXN][3], dist[MAXN][3];
int n, m;
void dijkstra(int v, int x){
for(int i=1; i<=n; i++){
dist[i][x] = INF;
}
priority_queue<pair<int, int>> q;
dist[v][x] = 0; q.push({0, v});
while(!q.empty()){
auto [d, v] = q.top(); q.pop();
if(marc[v][x]) continue;
marc[v][x] = 1;
for(auto [u, w] : adj[v]){
if(marc_edge[{v, u}]) w = 0;
if(dist[v][x] + w < dist[u][x]){
dist[u][x] = dist[v][x] + w;
q.push({-dist[u][x], u});
}
}
}
}
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
int s, t; cin >> s >> t;
int u, v; cin >> u >> v;
for(int i=1; i<=m; i++){
int a, b, c; cin >> a >> b >> c;
adj[a].push_back({b, c});
adj[b].push_back({a, c});
}
dijkstra(s, 0);
dijkstra(t, 1);
int min_dist = dist[t][0];
for(int i=1; i<=n; i++){
for(auto [j, w] : adj[i]){
if(dist[i][0] + dist[j][1] + w == min_dist){
marc_edge[{i, j}] = marc_edge[{j, i}] = 1;
}
}
}
dijkstra(u, 2);
cout << dist[v][2] << "\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... |